Skip to content

Comment on Never create Ruby strings longer than 23 charactersparent

Comments

Yeah. I just looked at the source because I was confused about how it knew how long the embedded string was (since the length field is in the other half of the union and ruby strings can have embedded \0 bytes), and RBasic is a struct containing a VALUE referring to a class and a VALUE "flags" that tends to have a lot of bit fiddling done to it.

Apparently out of the non-reserved bits, one is used to tell whether the string is embedded or not and five more are combined to give the string's length. Makes sense!

AboutSource Built by g1lg1l

Hackerly is an independent reader for Hacker News, built on the public HN API. Not affiliated with Y Combinator.