That said, yeah, it'd be nice if you could just make the assumption that if two objects point to the same memory, they're de facto identical...
That said, yeah, it'd be nice if you could just make the assumption that if two objects point to the same memory, they're de facto identical...
Sure, but we aren't talking Ruby semantics here, we're talking C. I don't see why it's useful to still have a sym_equal identifier that's just an alias for rb_obj_equal.
I'm the author of the article.
The optimization here is that the check for plain-old symbol equality is happening without the need for a full ruby method dispatch. You can't make that assumption in the general case, because it's possible to override equality in Ruby, which then requires more work.
If you look at the full source code for the method in question, you'll see that it does special checks for Fixnums and Floats and Strings, then a check for the default object equality (i.e. does the comparison use rb_obj_equal?), then, finally, it falls back to a full method call.