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$=$&$$$&%1!<%9$O$Ie(B
e$B$l$@$1$”$k$s$@$m$&$+!)e(B
mswin32
http://www.atdot.net/fp_store/f.0tse9l/file.graph.png
linux32 (on VirtualBox)
http://www.atdot.net/fp_store/f.7tse9l/file.graph.png
e$B%0%i%U$O!"e(B
e$B2#<4$,!V<:GT$9$ke(B when e$B$N?t!Je(Bst_foreach
e$B$G$?$I$k2s?t!K!We(B
e$B=D<4$,!V<B9T;~4V!JIC!K!We(B
e$B$G$9!#e(B
e$B$A$J$_$K!"$b$A$m$s%R%C%H$9$k$H$-$Oe(B when
e$B$N?t$O4X78$J$/B.$$$G$9!#e(B
e$B%F%9%H%3!<%I!'e(B
require ‘benchmark’
n = 10_000_000
Benchmark.bm{|x|
[true, false, Object.new].each{|obj|
20.times{|i|
ary = (0…i).to_a
obj = i if obj == true
x.report(“#{obj}\t#{i+1}”){
eval %Q{
n.times{
case obj
when #{ary.join(", ")}
# ignore
else
# ignore
end
}
}
}
}
}
}
e$B%Q%C%A!'e(B
Index: insns.def
— insns.def (revision 29350)
+++ insns.def (working copy)
@@ -1281,20 +1281,8 @@
}
break;
}
Index: vm_insnhelper.c
— vm_insnhelper.c (revision 29350)
+++ vm_insnhelper.c (working copy)
@@ -1699,22 +1699,3 @@
return Qundef;
}
-struct opt_case_dispatch_i_arg {
- VALUE obj;
- int label;
-};
-
-static int
-opt_case_dispatch_i(st_data_t key, st_data_t data, st_data_t p)
-{
- struct opt_case_dispatch_i_arg *arg = (void *)p;
-
- if (RTEST(rb_funcall((VALUE)key, idEqq, 1, arg->obj))) {
- arg->label = FIX2INT((VALUE)data);
- return ST_STOP;
- }
- else {
- return ST_CONTINUE;
- }
-}
-