Skip to content

Comment on Never create Ruby strings longer than 23 charactersparent

Comments

They probably are when they are inlined like this, else, how would you know the length?

The length is stored in a flag.

include/ruby/ruby.h:

    #define RSTRING_EMBED_LEN(str) \
         (long)((RBASIC(str)->flags >> RSTRING_EMBED_LEN_SHIFT) & \
                (RSTRING_EMBED_LEN_MASK >> RSTRING_EMBED_LEN_SHIFT))

    #define RSTRING_LEN(str) \
        (!(RBASIC(str)->flags & RSTRING_NOEMBED) ? \
         RSTRING_EMBED_LEN(str) : \
         RSTRING(str)->as.heap.len)
AboutSource Built by g1lg1l

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