Hacker News new | ask | show | jobs
by techjamie 767 days ago
Maybe the sheer amount that strings are getting iterated through makes storing length computationally cheaper? Unless you're using very optimized methods to work with the string, the majority of string operations involve a lot of iteration and comparison. Vectors, on the other hand, have much more varied use and possibly may never be iterated at all (though they likely will somewhere).
1 comments

> getting iterated through

So for loop conditions like

  for (size_t i = 0; i < str.size(); i++)
are cheaper to calculate?