Created
October 24, 2019 05:39
-
-
Save shyouhei/88f66d3dc8d90d75cf9e5264b2a217fc to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
From 98be06eba1e2f09bbfba9c63ec5f79581ad7a5fa Mon Sep 17 00:00:00 2001 | |
From: =?UTF-8?q?=E5=8D=9C=E9=83=A8=E6=98=8C=E5=B9=B3?= | |
<shyouhei@ruby-lang.org> | |
Date: Wed, 23 Oct 2019 17:10:10 +0900 | |
Subject: [PATCH] optimize CLASS_OF | |
--- | |
include/ruby/ruby.h | 28 +++++++++++++++++++--------- | |
1 file changed, 19 insertions(+), 9 deletions(-) | |
diff --git a/include/ruby/ruby.h b/include/ruby/ruby.h | |
index b144fa0111..4467db0755 100644 | |
--- a/include/ruby/ruby.h | |
+++ b/include/ruby/ruby.h | |
@@ -2094,17 +2094,27 @@ RUBY_EXTERN VALUE rb_stdin, rb_stdout, rb_stderr; | |
static inline VALUE | |
rb_class_of(VALUE obj) | |
{ | |
- if (RB_IMMEDIATE_P(obj)) { | |
- if (RB_FIXNUM_P(obj)) return rb_cInteger; | |
- if (RB_FLONUM_P(obj)) return rb_cFloat; | |
- if (obj == RUBY_Qtrue) return rb_cTrueClass; | |
- if (RB_STATIC_SYM_P(obj)) return rb_cSymbol; | |
+ if (!RB_SPECIAL_CONST_P(obj)) { | |
+ return RBASIC_CLASS(obj); | |
} | |
- else if (!RB_TEST(obj)) { | |
- if (obj == RUBY_Qnil) return rb_cNilClass; | |
- if (obj == RUBY_Qfalse) return rb_cFalseClass; | |
+ else if (obj == RUBY_Qfalse) { | |
+ return rb_cFalseClass; | |
+ } | |
+ else if (obj == RUBY_Qnil) { | |
+ return rb_cNilClass; | |
+ } | |
+ else if (obj == RUBY_Qtrue) { | |
+ return rb_cTrueClass; | |
+ } | |
+ else if (RB_FIXNUM_P(obj)) { | |
+ return rb_cInteger; | |
+ } | |
+ else if (RB_STATIC_SYM_P(obj)) { | |
+ return rb_cSymbol; | |
+ } | |
+ else { | |
+ return rb_cFloat; | |
} | |
- return RBASIC(obj)->klass; | |
} | |
static inline int | |
-- | |
2.17.1 | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Calculating ------------------------------------- | |
ours@clang-10 ours@gcc-9 ours@clang-9 master@clang-10 master@gcc-9 master@clang-9 | |
Optcarrot Lan_Master.nes 45.113 46.777 45.515 37.691 46.349 38.487 fps | |
Comparison: | |
Optcarrot Lan_Master.nes | |
ours@gcc-9: 46.8 fps | |
master@gcc-9: 46.3 fps - 1.01x slower | |
ours@clang-9: 45.5 fps - 1.03x slower | |
ours@clang-10: 45.1 fps - 1.04x slower | |
master@clang-9: 38.5 fps - 1.22x slower | |
master@clang-10: 37.7 fps - 1.24x slower |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment