[macruby-changes] [3016] MacRuby/trunk/ext/json/rubyext.c

source_changes at macosforge.org source_changes at macosforge.org
Mon Nov 16 13:20:39 PST 2009


Revision: 3016
          http://trac.macosforge.org/projects/ruby/changeset/3016
Author:   psychs at limechat.net
Date:     2009-11-16 13:20:36 -0800 (Mon, 16 Nov 2009)
Log Message:
-----------
eliminate rb_str_new for performance

Modified Paths:
--------------
    MacRuby/trunk/ext/json/rubyext.c

Modified: MacRuby/trunk/ext/json/rubyext.c
===================================================================
--- MacRuby/trunk/ext/json/rubyext.c	2009-11-16 20:21:05 UTC (rev 3015)
+++ MacRuby/trunk/ext/json/rubyext.c	2009-11-16 21:20:36 UTC (rev 3016)
@@ -196,16 +196,16 @@
 {
     const unsigned char* buffer;
     unsigned int len;
-    VALUE outBuff;
     rb_json_generator_t* gen = RJSONGenerator(self);
     
     json_encode_part(gen, obj);
-
     yajl_gen_get_buf(gen->generator, &buffer, &len);
-    outBuff = rb_str_new((const char*)buffer, len);
+    
+    VALUE resultBuf = (VALUE)CFStringCreateWithBytes(NULL, (const UInt8*)buffer, len, kCFStringEncodingUTF8, false);
+    CFMakeCollectable((CFTypeRef)resultBuf);
     yajl_gen_clear(gen->generator);
     
-    return outBuff;
+    return resultBuf;
 }
 
 static void
@@ -305,7 +305,9 @@
 static int
 yajl_handle_string(void* ctx, const unsigned char* value, unsigned int len)
 {
-    yajl_set_static_value(ctx, rb_str_new((const char*)value, len));
+    VALUE str = (VALUE)CFStringCreateWithBytes(NULL, (const UInt8*)value, len, kCFStringEncodingUTF8, false);
+    CFMakeCollectable((CFTypeRef)str);
+    yajl_set_static_value(ctx, str);
     return 1;
 }
 
@@ -313,8 +315,10 @@
 yajl_handle_hash_key(void* ctx, const unsigned char* value, unsigned int len)
 {
     rb_json_parser_t* parser = RJSONParser(ctx);
-    VALUE keyStr = rb_str_new((const char*)value, len);
     
+    VALUE keyStr = (VALUE)CFStringCreateWithBytes(NULL, (const UInt8*)value, len, kCFStringEncodingUTF8, false);
+    CFMakeCollectable((CFTypeRef)keyStr);
+    
     if (parser->symbolizeKeys) {
         ID key = rb_intern(RSTRING_PTR(keyStr));
         yajl_set_static_value(ctx, ID2SYM(key));
@@ -501,9 +505,11 @@
     
     str = rb_funcall(self, id_to_s, 0);
     
-    buf = rb_str_new2("\"");
-    buf = rb_str_append(buf, str);
-    buf = rb_str_buf_cat2(buf, "\"");
+    buf = (VALUE)CFStringCreateMutable(NULL, 0);
+    CFMakeCollectable((CFTypeRef)buf);
+    CFStringAppendCString((CFMutableStringRef)buf, "\"", kCFStringEncodingUTF8);
+    CFStringAppend((CFMutableStringRef)buf, (CFStringRef)str);
+    CFStringAppendCString((CFMutableStringRef)buf, "\"", kCFStringEncodingUTF8);
     return buf;
 }
 
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/macruby-changes/attachments/20091116/90115123/attachment.html>


More information about the macruby-changes mailing list