[svn:parrot] r46042 - branches/compact_pool_revamp/src/string

chromatic at svn.parrot.org chromatic at svn.parrot.org
Mon Apr 26 20:40:45 UTC 2010


Author: chromatic
Date: Mon Apr 26 20:40:44 2010
New Revision: 46042
URL: https://trac.parrot.org/parrot/changeset/46042

Log:
[string] Revised string_make() to default to the ASCII charset when not given a
C string naming the desired charset, because looking up charset by STRING name
with a linear search is silly and expensive.  Made Parrot_str_from_uint() use
the default charset, which speeds up stress_strings by 4.432%.  Yes, it's a
distortion in the benchmark, but O(n) with a small n repeated a few million
times is still slower than O(1).

Modified:
   branches/compact_pool_revamp/src/string/api.c

Modified: branches/compact_pool_revamp/src/string/api.c
==============================================================================
--- branches/compact_pool_revamp/src/string/api.c	Mon Apr 26 20:39:50 2010	(r46041)
+++ branches/compact_pool_revamp/src/string/api.c	Mon Apr 26 20:40:44 2010	(r46042)
@@ -651,18 +651,17 @@
     ASSERT_ARGS(string_make)
     const CHARSET *charset;
 
-    if (!charset_name)
-        charset_name = "ascii";
-
-    charset = Parrot_find_charset(interp, charset_name);
-
-    if (!charset)
-        Parrot_ex_throw_from_c_args(interp, NULL, EXCEPTION_UNIMPLEMENTED,
-            "Can't make '%s' charset strings", charset_name);
+    if (charset_name) {
+        charset = Parrot_find_charset(interp, charset_name);
+        if (!charset)
+            Parrot_ex_throw_from_c_args(interp, NULL, EXCEPTION_UNIMPLEMENTED,
+                "Can't make '%s' charset strings", charset_name);
+    }
+    else
+        charset = Parrot_get_charset(interp, 0);
 
     return Parrot_str_new_init(interp, buffer, len,
         charset->preferred_encoding, charset, flags);
-
 }
 
 
@@ -3186,7 +3185,7 @@
     if (minus)
         *--p = '-';
 
-    return string_make(interp, p, (UINTVAL)(tail - p), "ascii", 0);
+    return string_make(interp, p, (UINTVAL)(tail - p), NULL, 0);
 }
 
 


More information about the parrot-commits mailing list