News for hackers. Stuff that matters.
Re:Never create Ruby strings longer than 23 characters by nly on Wednesday December 11, 2013 @10:39AM (#6888102)
This is known as the "small string optimisation" in C++, so you can see a similar implementation in Clangs libc++[1].

One interesting corollary is that moving short strings in an implementation that does this could actually be ever so slightly (negligibly) slower than moving long ones (since byte copies are slower than word copies). But generally, this is a free lunch optimisation and can save you hundreds of megs of memory when writing programs dealing with millions of short strings.

[1] http://llvm.org/svn/llvm-project/libcxx/trunk/include/string - search for "union"

There are no comments on this comment yet.