[macruby-changes] [5112] MacRuby/trunk/symbol.c

source_changes at macosforge.org source_changes at macosforge.org
Mon Jan 3 20:11:54 PST 2011


Revision: 5112
          http://trac.macosforge.org/projects/ruby/changeset/5112
Author:   lsansonetti at apple.com
Date:     2011-01-03 20:11:50 -0800 (Mon, 03 Jan 2011)
Log Message:
-----------
avoid grabbing the uchar buffer twice

Modified Paths:
--------------
    MacRuby/trunk/symbol.c

Modified: MacRuby/trunk/symbol.c
===================================================================
--- MacRuby/trunk/symbol.c	2011-01-04 04:08:31 UTC (rev 5111)
+++ MacRuby/trunk/symbol.c	2011-01-04 04:11:50 UTC (rev 5112)
@@ -49,19 +49,18 @@
 ID
 rb_intern_str(VALUE str)
 {
-    const unsigned long name_hash = rb_str_hash(str);
+    UChar *chars = NULL;
+    long chars_len = 0;
+    bool need_free = false;
+    rb_str_get_uchars(str, &chars, &chars_len, &need_free);
+
+    const unsigned long name_hash = rb_str_hash_uchars(chars, chars_len);
     ID id = (ID)CFDictionaryGetValue(sym_id, (const void *)name_hash); 
     if (id != 0) {
-	return id;
+	goto return_id;
     } 
 
     rb_sym_t *sym = NULL;
-
-    UChar *chars = NULL;
-    long chars_len = 0;
-    bool need_free = false;
-    rb_str_get_uchars(str, &chars, &chars_len, &need_free);
-
     long pos = 0;
     if (chars_len > 0) {
 	UChar c = chars[0];
@@ -121,6 +120,7 @@
     CFDictionarySetValue(sym_id, (const void *)name_hash, (const void *)id);
     CFDictionarySetValue(id_str, (const void *)id, (const void *)sym);
 
+return_id:
     if (need_free) {
 	free(chars);
     }
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/macruby-changes/attachments/20110103/4ab944d2/attachment.html>


More information about the macruby-changes mailing list