MRI: use RB_TYPE_P() instead of rb_type() #57

Merged
cremno merged 1 commits from mri-use-rb_type_p-instead-of-rb_type into master 2014-08-30 01:56:37 +00:00
cremno commented 2014-08-29 10:57:53 +00:00 (Migrated from github.com)

Nothing important, but I'm currently fixing some issues with rb_get_args and I've noticed that almost everywhere RB_TYPE_P (which selects the right comparison) can be used instead of rb_type (which most probably doesn't).

Nothing important, but I'm currently fixing some issues with `rb_get_args` and I've noticed that almost everywhere `RB_TYPE_P` (which selects the right comparison) can be used instead of `rb_type` (which most probably doesn't).
Ancurio commented 2014-08-29 20:34:09 +00:00 (Migrated from github.com)

Thanks, this is fine, but what do you mean by "rb_type most probably doesn't select the right comparison"?

Thanks, this is fine, but what do you mean by "rb_type most probably doesn't select the right comparison"?
cremno commented 2014-08-29 20:49:01 +00:00 (Migrated from github.com)

I'm not good with words. It supports an optimizing compiler in selecting the right comparison: 7df9a77da1/include/ruby/ruby.h (L1605-L1613)

So if you write RB_TYPE_P(obj, T_STRING) everything else than (!SPECIAL_CONST_P(obj) && BUILTIN_TYPE(obj) == (T_STRING)) gets eliminated because it's dead code. rb_type sometimes doesn't even get inlined.

I'm not good with words. It supports an optimizing compiler in selecting the right comparison: https://github.com/ruby/ruby/blob/7df9a77da1947c617662148f6485dc58967277f2/include/ruby/ruby.h#L1605-L1613 So if you write `RB_TYPE_P(obj, T_STRING)` everything else than `(!SPECIAL_CONST_P(obj) && BUILTIN_TYPE(obj) == (T_STRING))` gets eliminated because it's dead code. `rb_type` sometimes doesn't even get inlined.
Ancurio commented 2014-08-30 02:06:53 +00:00 (Migrated from github.com)

I was aware rb_type was a function, the way it looked to me it seemed every optimizing compiler would reduce it into more or less how RB_TYPE_P looks (ie. a bunch of inline cmp/branches).

I was aware `rb_type` was a function, the way it looked to me it seemed every optimizing compiler would reduce it into more or less how `RB_TYPE_P` looks (ie. a bunch of inline cmp/branches).
Sign in to join this conversation.
No reviewers
No Milestone
No project
No Assignees
1 Participants
Notifications
Due Date
The due date is invalid or out of range. Please use the format 'yyyy-mm-dd'.

No due date set.

Dependencies

No dependencies set.

Reference: MapleShrine/mkxp#57
No description provided.