[macruby-changes] [3628] MacRuby/branches/icu

source_changes at macosforge.org source_changes at macosforge.org
Thu Feb 25 17:25:34 PST 2010


Revision: 3628
          http://trac.macosforge.org/projects/ruby/changeset/3628
Author:   lsansonetti at apple.com
Date:     2010-02-25 17:25:31 -0800 (Thu, 25 Feb 2010)
Log Message:
-----------
better string/symbol interaction

Modified Paths:
--------------
    MacRuby/branches/icu/encoding.h
    MacRuby/branches/icu/string.c

Modified: MacRuby/branches/icu/encoding.h
===================================================================
--- MacRuby/branches/icu/encoding.h	2010-02-26 01:07:51 UTC (rev 3627)
+++ MacRuby/branches/icu/encoding.h	2010-02-26 01:25:31 UTC (rev 3628)
@@ -290,7 +290,9 @@
 	    STRING_VALID_ENCODING);
 }
 
+VALUE mr_enc_s_is_compatible(VALUE klass, SEL sel, VALUE str1, VALUE str2);
 VALUE str_inspect(rb_str_t *str, bool dump);
+VALUE rb_str_intern_fast(VALUE str);
 
 // The following functions should always been prefered over anything else,
 // especially if this "else" is RSTRING_PTR and RSTRING_LEN.
@@ -303,8 +305,6 @@
 void rb_str_append_uchar(VALUE str, UChar c);
 unsigned long rb_str_hash_uchars(const UChar *chars, long chars_len);
 
-VALUE mr_enc_s_is_compatible(VALUE klass, SEL sel, VALUE str1, VALUE str2);
-
 // Return a string object appropriate for bstr_ calls. This does nothing for
 // data/binary RubyStrings.
 VALUE rb_str_bstr(VALUE str);

Modified: MacRuby/branches/icu/string.c
===================================================================
--- MacRuby/branches/icu/string.c	2010-02-26 01:07:51 UTC (rev 3627)
+++ MacRuby/branches/icu/string.c	2010-02-26 01:25:31 UTC (rev 3628)
@@ -1035,8 +1035,17 @@
 static rb_str_t *
 str_need_string(VALUE str)
 {
-    if (TYPE(str) != T_STRING) {
-	str = rb_str_to_str(str);
+    switch (TYPE(str)) {
+	case T_SYMBOL:
+	    str = rb_sym2str(str);
+	    break;
+
+	case T_STRING:
+	    break;
+
+	default:
+	    str = rb_str_to_str(str);
+	    break;
     }
     return IS_RSTR(str)
 	? (rb_str_t *)str : str_new_from_cfstring((CFStringRef)str);
@@ -1948,8 +1957,7 @@
     if (OBJ_TAINTED(self) && rb_safe_level() >= 1) {
 	rb_raise(rb_eSecurityError, "Insecure: can't intern tainted string");
     }
-    str_make_data_binary(RSTR(self));
-    return ID2SYM(rb_intern(RSTR(self)->data.bytes));
+    return rb_str_intern_fast(self);
 }
 
 /*
@@ -3441,6 +3449,13 @@
     return str;
 }
 
+VALUE
+rb_str_intern_fast(VALUE str)
+{
+    // TODO: this currently does 2 hash lookups, could be optimized.
+    return ID2SYM(rb_intern_str(str));
+}
+
 // MRI C-API compatibility.
 
 VALUE
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/macruby-changes/attachments/20100225/7da706a3/attachment-0001.html>


More information about the macruby-changes mailing list