Created
August 18, 2009 14:15
-
-
Save nagachika/169731 to your computer and use it in GitHub Desktop.
This patch add new instruction opt_size to ruby-1.9
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
Index: insns.def | |
=================================================================== | |
--- insns.def (revision 24573) | |
+++ insns.def (working copy) | |
@@ -1945,6 +1945,39 @@ | |
/** | |
@c optimize | |
+ @e optimized size | |
+ @j 最適化された recv.size()。 | |
+ */ | |
+DEFINE_INSN | |
+opt_size | |
+() | |
+(VALUE recv) | |
+(VALUE val) | |
+{ | |
+ if (!SPECIAL_CONST_P(recv) && | |
+ BASIC_OP_UNREDEFINED_P(BOP_SIZE)) { | |
+ if (HEAP_CLASS_OF(recv) == rb_cString) { | |
+ val = rb_str_length(recv); | |
+ } | |
+ else if (HEAP_CLASS_OF(recv) == rb_cArray) { | |
+ val = LONG2FIX(RARRAY_LEN(recv)); | |
+ } | |
+ else if (HEAP_CLASS_OF(recv) == rb_cHash) { | |
+ val = INT2FIX(RHASH_SIZE(recv)); | |
+ } | |
+ else { | |
+ goto INSN_LABEL(normal_dispatch); | |
+ } | |
+ } | |
+ else { | |
+ INSN_LABEL(normal_dispatch): | |
+ PUSH(recv); | |
+ CALL_SIMPLE_METHOD(0, idSize, recv); | |
+ } | |
+} | |
+ | |
+/** | |
+ @c optimize | |
@e optimized succ | |
@j 最適化された recv.succ()。 | |
*/ | |
Index: compile.c | |
=================================================================== | |
--- compile.c (revision 24573) | |
+++ compile.c (working copy) | |
@@ -1801,6 +1801,9 @@ | |
if (mid == idLength) { | |
insn_set_specialized_instruction(iobj, BIN(opt_length)); | |
} | |
+ else if (mid == idSize) { | |
+ insn_set_specialized_instruction(iobj, BIN(opt_size)); | |
+ } | |
else if (mid == idSucc) { | |
insn_set_specialized_instruction(iobj, BIN(opt_succ)); | |
} | |
Index: id.c | |
=================================================================== | |
--- id.c (revision 24573) | |
+++ id.c (working copy) | |
@@ -34,6 +34,7 @@ | |
REGISTER_SYMID(idEach, "each"); | |
REGISTER_SYMID(idLength, "length"); | |
+ REGISTER_SYMID(idSize, "size"); | |
REGISTER_SYMID(idLambda, "lambda"); | |
REGISTER_SYMID(idIntern, "intern"); | |
REGISTER_SYMID(idGets, "gets"); | |
Index: id.h | |
=================================================================== | |
--- id.h (revision 24573) | |
+++ id.h (working copy) | |
@@ -98,6 +98,7 @@ | |
tIntern, | |
tMethodMissing, | |
tLength, | |
+ tSize, | |
tGets, | |
tSucc, | |
tEach, | |
@@ -118,6 +119,7 @@ | |
TOKEN2ID(Intern), | |
TOKEN2ID(MethodMissing), | |
TOKEN2ID(Length), | |
+ TOKEN2ID(Size), | |
TOKEN2ID(Gets), | |
TOKEN2ID(Succ), | |
TOKEN2ID(Each), | |
Index: vm_insnhelper.h | |
=================================================================== | |
--- vm_insnhelper.h (revision 24573) | |
+++ vm_insnhelper.h (working copy) | |
@@ -48,6 +48,7 @@ | |
BOP_AREF, | |
BOP_ASET, | |
BOP_LENGTH, | |
+ BOP_SIZE, | |
BOP_SUCC, | |
BOP_GT, | |
BOP_GE, |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment