Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

faster #<<, #[] and #[]=

git-svn-id: http://svn.macosforge.org/repository/ruby/MacRuby/trunk@4099 23306eb0-4c56-4727-a40e-e92c0eb68959
  • Loading branch information...
commit 57e1af974c479b7b6727c0e4c7c816d47f0b0d87 1 parent 03f06a0
Laurent Sansonetti authored
Showing with 25 additions and 44 deletions.
  1. +23 −43 dispatcher.cpp
  2. +1 −0  encoding.h
  3. +1 −1  string.c
View
66 dispatcher.cpp
@@ -1347,21 +1347,12 @@ rb_vm_fast_shift(VALUE obj, VALUE other, struct mcache *cache,
unsigned char overriden)
{
if (overriden == 0) {
- switch (TYPE(obj)) {
- case T_ARRAY:
- if (*(VALUE *)obj == rb_cRubyArray) {
- return rary_push_m(obj, 0, other);
- }
- break;
-
-#if 0 // TODO
- case T_STRING:
- if (*(VALUE *)obj == rb_cCFString) {
- rb_str_concat(obj, other);
- return obj;
- }
- break;
-#endif
+ VALUE klass = CLASS_OF(obj);
+ if (klass == rb_cRubyArray) {
+ return rary_push_m(obj, 0, other);
+ }
+ else if (klass == rb_cRubyString) {
+ return rstr_concat(obj, 0, other);
}
}
return __rb_vm_dispatch(GET_VM(), cache, 0, obj, NULL, selLTLT, NULL, 0, 1,
@@ -1373,19 +1364,14 @@ VALUE
rb_vm_fast_aref(VALUE obj, VALUE other, struct mcache *cache,
unsigned char overriden)
{
- if (overriden == 0)
- switch (TYPE(obj)) {
- case T_ARRAY:
- if (*(VALUE *)obj == rb_cRubyArray) {
- return rary_aref(obj, 0, 1, &other);
- }
- break;
-
- case T_HASH:
- if (*(VALUE *)obj == rb_cRubyHash) {
- return rhash_aref(obj, 0, other);
- }
- break;
+ if (overriden == 0) {
+ VALUE klass = CLASS_OF(obj);
+ if (klass == rb_cRubyArray) {
+ return rary_aref(obj, 0, 1, &other);
+ }
+ else if (klass == rb_cRubyHash) {
+ return rhash_aref(obj, 0, other);
+ }
}
return __rb_vm_dispatch(GET_VM(), cache, 0, obj, NULL, selAREF, NULL, 0, 1,
&other);
@@ -1397,21 +1383,15 @@ rb_vm_fast_aset(VALUE obj, VALUE other1, VALUE other2, struct mcache *cache,
unsigned char overriden)
{
if (overriden == 0) {
- switch (TYPE(obj)) {
- case T_ARRAY:
- if (*(VALUE *)obj == rb_cRubyArray) {
- if (TYPE(other1) == T_FIXNUM) {
- rary_store(obj, FIX2LONG(other1), other2);
- return other2;
- }
- }
- break;
-
- case T_HASH:
- if (*(VALUE *)obj == rb_cRubyHash) {
- return rhash_aset(obj, 0, other1, other2);
- }
- break;
+ VALUE klass = CLASS_OF(obj);
+ if (klass == rb_cRubyArray) {
+ if (TYPE(other1) == T_FIXNUM) {
+ rary_store(obj, FIX2LONG(other1), other2);
+ return other2;
+ }
+ }
+ else if (klass == rb_cRubyHash) {
+ return rhash_aset(obj, 0, other1, other2);
}
}
VALUE args[2] = { other1, other2 };
View
1  encoding.h
@@ -303,6 +303,7 @@ VALUE rstr_swapcase(VALUE str, SEL sel);
VALUE rstr_capitalize(VALUE str, SEL sel);
VALUE rstr_upcase(VALUE str, SEL sel);
VALUE rstr_downcase(VALUE str, SEL sel);
+VALUE rstr_concat(VALUE self, SEL sel, VALUE other);
// The following functions should always been prefered over anything else,
// especially if this "else" is RSTRING_PTR and RSTRING_LEN.
View
2  string.c
@@ -2573,7 +2573,7 @@ rstr_format(VALUE str, SEL sel, VALUE arg)
* a.concat(33) #=> "hello world!"
*/
-static VALUE
+VALUE
rstr_concat(VALUE self, SEL sel, VALUE other)
{
rstr_modify(self);
Please sign in to comment.
Something went wrong with that request. Please try again.