[macruby-changes] [1555] MacRuby/branches/experimental

source_changes at macosforge.org source_changes at macosforge.org
Thu May 7 19:36:37 PDT 2009


Revision: 1555
          http://trac.macosforge.org/projects/ruby/changeset/1555
Author:   lsansonetti at apple.com
Date:     2009-05-07 19:36:37 -0700 (Thu, 07 May 2009)
Log Message:
-----------
faster String#<< + faster str_modifiable() check

Modified Paths:
--------------
    MacRuby/branches/experimental/roxor.cpp
    MacRuby/branches/experimental/string.c

Modified: MacRuby/branches/experimental/roxor.cpp
===================================================================
--- MacRuby/branches/experimental/roxor.cpp	2009-05-08 01:30:19 UTC (rev 1554)
+++ MacRuby/branches/experimental/roxor.cpp	2009-05-08 02:36:37 UTC (rev 1555)
@@ -7907,9 +7907,16 @@
 rb_vm_fast_shift(VALUE obj, VALUE other, struct mcache *cache,
 		 unsigned char overriden)
 {
-    if (overriden == 0 && TYPE(obj) == T_ARRAY) {
-	rb_ary_push(obj, other);
-	return obj;
+    if (overriden == 0) {
+	switch (TYPE(obj)) {
+	    case T_ARRAY:
+		rb_ary_push(obj, other);
+		return obj;
+
+	    case T_STRING:
+		rb_str_concat(obj, other);
+		return obj;
+	}
     }
     return __rb_vm_dispatch(cache, obj, NULL, selLTLT, 0, 1, &other);
 }

Modified: MacRuby/branches/experimental/string.c
===================================================================
--- MacRuby/branches/experimental/string.c	2009-05-08 01:30:19 UTC (rev 1554)
+++ MacRuby/branches/experimental/string.c	2009-05-08 02:36:37 UTC (rev 1555)
@@ -486,16 +486,21 @@
 static inline void
 str_modifiable(VALUE str)
 {
-    if (*(VALUE *)str == rb_cCFString) {
-	if (RSTRING_IMMUTABLE(str)) {
-	    rb_raise(rb_eRuntimeError, "can't modify immutable string");
-	}
+    long mask;
+#ifdef __LP64__
+    mask = RCLASS_RC_FLAGS(str);
+#else
+    mask = rb_objc_flag_get_mask((void *)str);
+#endif
+    if (RSTRING_IMMUTABLE(str)) {
+	mask |= FL_FREEZE;
     }
-    if (OBJ_FROZEN(str)) {
-	rb_error_frozen("string");
+    if ((mask & FL_FREEZE) == FL_FREEZE) {
+	rb_raise(rb_eRuntimeError, "can't modify frozen/immutable string");
     }
-    if (!OBJ_TAINTED(str) && rb_safe_level() >= 4)
+    if ((mask & FL_TAINT) == FL_TAINT && rb_safe_level() >= 4) {
 	rb_raise(rb_eSecurityError, "Insecure: can't modify string");
+    }
 }
 
 void
@@ -703,6 +708,7 @@
     return str;
 }
 
+__attribute__((always_inline))
 static void
 rb_objc_str_cat(VALUE str, const char *ptr, long len, int cfstring_encoding)
 {
@@ -785,8 +791,8 @@
     return str;
 }
 
-VALUE
-rb_str_buf_append(VALUE str, VALUE str2)
+static inline VALUE
+rb_str_buf_append0(VALUE str, VALUE str2)
 {
     if (TYPE(str2) != T_SYMBOL) {
 	Check_Type(str2, T_STRING);
@@ -804,11 +810,17 @@
 }
 
 VALUE
+rb_str_buf_append(VALUE str, VALUE str2)
+{
+   return rb_str_buf_append0(str, str2);
+}
+
+VALUE
 rb_str_append(VALUE str, VALUE str2)
 {
     StringValue(str2);
     rb_str_modify(str);
-    return rb_str_buf_append(str, str2);
+    return rb_str_buf_append0(str, str2);
 }
 
 
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/macruby-changes/attachments/20090507/76a094c3/attachment.html>


More information about the macruby-changes mailing list