Skip to content

Comment on Never create Ruby strings longer than 23 characters

Comments

http://www.slideshare.net/nirusuma/what-lies-beneath-the-bea... (from march 2012) also discusses this.

Also (pedantic):

   #define RSTRING_EMBED_LEN_MAX ((int)((sizeof(VALUE)*3)/sizeof(char)-1))
sizeof(char) is always 1, so that division is superfluous.

sizeof(char) is implementation defined; see limits.h for more information on the probable size of char for your target. If the sizeof(char) is 1, the division will be optimized away, so there's no loss by keeping the code portable.

No, the size of char (in bits) is implementation defined, but sizeof(char) is defined to be 1, no matter what its size in bits.

No this is incorrect, see:

http://stackoverflow.com/q/4562249/25981

sizeof(char) is always defined to be one. This can't be altered by a conforming compiler.

Wrong. sizeof(char) is define to be one. The number of bits in a byte (char) is implementation defined (this is why CHAR_BIT exists). Not the same thing.

AboutSource Built by g1lg1l

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