3 ms·
It is uintptr_t in size, but it's actually a bit more complicated than that. If the 'value' is a fixnum, the low bit is set to 1 and the bottom 31 or 63 bits of
by stormbrew 12y ago
It is uintptr_t in size, but it's actually a bit more complicated than that. If the 'value' is a fixnum, the low bit is set to 1 and the bottom 31 or 63 bits of the integer are shifted to the left and stored directly in the VALUE [1].
And then there's a few other bit patterns (all with the low bit set to zero) that also mean embedded values [2], including symbols, where they're actually an index into a string table rather than an actual object pointer.
So a lot of the time, VALUE is anything but a misnomer. Also, the name for this pattern is tagged pointer. It's one of the most notable things ruby borrowed from emacs lisp [3].
Also, the entire point of symbols is that they don't need to be dereferenced (or strcmp'd) to compare them. That's not the slow part of symbol comparison.
[1] https://github.com/ruby/ruby/blob/trunk/include/ruby/ruby.h#L234 https://github.com/ruby/ruby/blob/trunk/include/ruby/ruby.h#...
[2] https://github.com/ruby/ruby/blob/trunk/include/ruby/ruby.h#L383 https://github.com/ruby/ruby/blob/trunk/include/ruby/ruby.h#...
[3] https://www.gnu.org/software/emacs/manual/html_node/elisp/Object-Internals.html https://www.gnu.org/software/emacs/manual/html_node/elisp/Ob...