Author: Antonio Cuni <[email protected]>
Branch: improve-str2charp
Changeset: r65265:771e378d592d
Date: 2013-07-08 15:56 +0200
http://bitbucket.org/pypy/pypy/changeset/771e378d592d/

Log:    use the new copy_string_to_raw to implement str2charp.
        Microbenchmarks show a speedup of 31x

diff --git a/rpython/rtyper/lltypesystem/rffi.py 
b/rpython/rtyper/lltypesystem/rffi.py
--- a/rpython/rtyper/lltypesystem/rffi.py
+++ b/rpython/rtyper/lltypesystem/rffi.py
@@ -677,7 +677,8 @@
 def make_string_mappings(strtype):
 
     if strtype is str:
-        from rpython.rtyper.lltypesystem.rstr import STR as STRTYPE
+        from rpython.rtyper.lltypesystem.rstr import (STR as STRTYPE,
+                                                      copy_string_to_raw)
         from rpython.rtyper.annlowlevel import llstr as llstrtype
         from rpython.rtyper.annlowlevel import hlstr as hlstrtype
         TYPEP = CCHARP
@@ -685,7 +686,9 @@
         lastchar = '\x00'
         builder_class = StringBuilder
     else:
-        from rpython.rtyper.lltypesystem.rstr import UNICODE as STRTYPE
+        from rpython.rtyper.lltypesystem.rstr import (
+            UNICODE as STRTYPE,
+            copy_unicode_to_raw as copy_string_to_raw)
         from rpython.rtyper.annlowlevel import llunicode as llstrtype
         from rpython.rtyper.annlowlevel import hlunicode as hlstrtype
         TYPEP = CWCHARP
@@ -702,11 +705,9 @@
         else:
             array = lltype.malloc(TYPEP.TO, len(s) + 1, flavor='raw', 
track_allocation=False)
         i = len(s)
+        ll_s = llstrtype(s)
+        copy_string_to_raw(ll_s, array, 0, i)
         array[i] = lastchar
-        i -= 1
-        while i >= 0:
-            array[i] = s[i]
-            i -= 1
         return array
     str2charp._annenforceargs_ = [strtype, bool]
 
diff --git a/rpython/rtyper/lltypesystem/rstr.py 
b/rpython/rtyper/lltypesystem/rstr.py
--- a/rpython/rtyper/lltypesystem/rstr.py
+++ b/rpython/rtyper/lltypesystem/rstr.py
@@ -102,7 +102,7 @@
     return copy_string_to_raw, copy_string_contents
 
 copy_string_to_raw, copy_string_contents = _new_copy_contents_fun(STR, Char, 
'string')
-copy_unicode_do_raw, copy_unicode_contents = _new_copy_contents_fun(UNICODE,
+copy_unicode_to_raw, copy_unicode_contents = _new_copy_contents_fun(UNICODE,
                                                                     UniChar, 
'unicode')
 
 CONST_STR_CACHE = WeakValueDictionary()
_______________________________________________
pypy-commit mailing list
[email protected]
http://mail.python.org/mailman/listinfo/pypy-commit

Reply via email to