[pypy-svn] r65749 - in pypy/trunk/pypy: rpython rpython/lltypesystem rpython/ootypesystem translator/jvm/src/pypy

cfbolz at codespeak.net cfbolz at codespeak.net
Fri Jun 12 17:28:30 CEST 2009


Author: cfbolz
Date: Fri Jun 12 17:28:30 2009
New Revision: 65749

Modified:
   pypy/trunk/pypy/rpython/lltypesystem/rstr.py
   pypy/trunk/pypy/rpython/ootypesystem/ootype.py
   pypy/trunk/pypy/rpython/ootypesystem/rstr.py
   pypy/trunk/pypy/rpython/rstr.py
   pypy/trunk/pypy/translator/jvm/src/pypy/PyPy.java
Log:
Use the same splitlines implementation for ootypesystem and lltypesystem. This allows us to
not have to implement it in all the ootype backends. Thus kill the JVM
implementation.


Modified: pypy/trunk/pypy/rpython/lltypesystem/rstr.py
==============================================================================
--- pypy/trunk/pypy/rpython/lltypesystem/rstr.py	(original)
+++ pypy/trunk/pypy/rpython/lltypesystem/rstr.py	Fri Jun 12 17:28:30 2009
@@ -674,35 +674,6 @@
         s1.copy_contents(s1, newstr, 0, 0, newlen)
         return newstr
 
-    def ll_splitlines(LIST, s, keep_newlines):
-        chars = s.chars
-        strlen = len(chars)
-        i = 0
-        j = 0
-        # The annotator makes sure this list is resizable.
-        res = LIST.ll_newlist(0)
-        while j < strlen:
-            while i < strlen and chars[i] != '\n' and chars[i] != '\r':
-                i += 1
-            eol = i
-            if i < strlen:
-                if chars[i] == '\r' and i + 1 < strlen and chars[i + 1] == '\n':
-                    i += 2
-                else:
-                    i += 1
-                if keep_newlines:
-                    eol = i
-            list_length = res.ll_length()
-            res._ll_resize_ge(list_length + 1)
-            item = res.ll_items()[list_length] = s.malloc(eol - j)
-            item.copy_contents(s, item, j, 0, eol - j)
-            j = i
-        if j < strlen:
-            list_length = res.ll_length()
-            res._ll_resize_ge(list_length + 1)
-            item = res.ll_items()[list_length] = s.malloc(strlen - j)
-            item.copy_contents(s, item, j, 0, strlen - j)
-        return res
 
     def ll_split_chr(LIST, s, c):
         chars = s.chars

Modified: pypy/trunk/pypy/rpython/ootypesystem/ootype.py
==============================================================================
--- pypy/trunk/pypy/rpython/ootypesystem/ootype.py	(original)
+++ pypy/trunk/pypy/rpython/ootypesystem/ootype.py	Fri Jun 12 17:28:30 2009
@@ -368,7 +368,6 @@
             "ll_lower": Meth([], self.SELFTYPE_T),
             "ll_substring": Meth([Signed, Signed], self.SELFTYPE_T), # ll_substring(start, count)
             "ll_split_chr": Meth([self.CHAR], Array(self.SELFTYPE_T)),
-            "ll_splitlines": Meth([Bool], Array(self.SELFTYPE_T)),
             "ll_contains": Meth([self.CHAR], Bool),
             "ll_replace_chr_chr": Meth([self.CHAR, self.CHAR], self.SELFTYPE_T),
             })
@@ -1290,12 +1289,6 @@
         # NOT_RPYTHON
         return self.make_string(self._str[start:start+count])
 
-    def ll_splitlines(self, keep_newlines):
-        l = [self.make_string(s) for s in self._str.splitlines(keep_newlines)]
-        res = _array(Array(self._TYPE), len(l))
-        res._array[:] = l
-        return res
-
     def ll_split_chr(self, ch):
         # NOT_RPYTHON
         l = [self.make_string(s) for s in self._str.split(ch)]

Modified: pypy/trunk/pypy/rpython/ootypesystem/rstr.py
==============================================================================
--- pypy/trunk/pypy/rpython/ootypesystem/rstr.py	(original)
+++ pypy/trunk/pypy/rpython/ootypesystem/rstr.py	Fri Jun 12 17:28:30 2009
@@ -207,9 +207,6 @@
     def ll_stringslice_minusone(s):
         return s.ll_substring(0, s.ll_strlen()-1)
 
-    def ll_splitlines(RESULT, s, keep_newlines):
-        return RESULT.ll_convert_from_array(s.ll_splitlines(keep_newlines))
-
     def ll_split_chr(RESULT, s, c):
         return RESULT.ll_convert_from_array(s.ll_split_chr(c))
 

Modified: pypy/trunk/pypy/rpython/rstr.py
==============================================================================
--- pypy/trunk/pypy/rpython/rstr.py	(original)
+++ pypy/trunk/pypy/rpython/rstr.py	Fri Jun 12 17:28:30 2009
@@ -7,7 +7,7 @@
 from pypy.rpython.rtuple import AbstractTupleRepr
 from pypy.rpython import rint
 from pypy.rpython.lltypesystem.lltype import Signed, Bool, Void, UniChar,\
-     cast_primitive
+     cast_primitive, typeOf
 
 class AbstractStringRepr(Repr):
     pass
@@ -732,3 +732,36 @@
             raise ValueError
 
         return parts_to_float(sign, before_point, after_point, exponent)
+
+    def ll_splitlines(cls, LIST, ll_str, keep_newlines):
+        from pypy.rpython.annlowlevel import hlstr
+        s = hlstr(ll_str)
+        STR = typeOf(ll_str)
+        strlen = len(s)
+        i = 0
+        j = 0
+        # The annotator makes sure this list is resizable.
+        res = LIST.ll_newlist(0)
+        while j < strlen:
+            while i < strlen and s[i] != '\n' and s[i] != '\r':
+                i += 1
+            eol = i
+            if i < strlen:
+                if s[i] == '\r' and i + 1 < strlen and s[i + 1] == '\n':
+                    i += 2
+                else:
+                    i += 1
+                if keep_newlines:
+                    eol = i
+            list_length = res.ll_length()
+            res._ll_resize_ge(list_length + 1)
+            item = cls.ll_stringslice_startstop(ll_str, j, eol)
+            res.ll_setitem_fast(list_length, item)
+            j = i
+        if j < strlen:
+            list_length = res.ll_length()
+            res._ll_resize_ge(list_length + 1)
+            item = cls.ll_stringslice_startstop(ll_str, j, strlen)
+            res.ll_setitem_fast(list_length, item)
+        return res
+    ll_splitlines = classmethod(ll_splitlines)

Modified: pypy/trunk/pypy/translator/jvm/src/pypy/PyPy.java
==============================================================================
--- pypy/trunk/pypy/translator/jvm/src/pypy/PyPy.java	(original)
+++ pypy/trunk/pypy/translator/jvm/src/pypy/PyPy.java	Fri Jun 12 17:28:30 2009
@@ -746,36 +746,6 @@
         return str.substring(start, end);
     }
 
-    public static Object[] ll_splitlines(String str, boolean keep_newlines) {
-        ArrayList lines = new ArrayList();
-        int i = 0, j = 0;
-        int length = str.length();
-        while (i < length) {
-            int eol;
-            while (i < length && str.charAt(i) != '\n' && str.charAt(i) != '\r') {
-                i++;
-            }
-            eol = i;
-            if (i < length) {
-                if (str.charAt(i) == '\r' && i + 1 < length &&
-                    str.charAt(i + 1) == '\n') {
-                    i += 2;
-                } else {
-                    i++;
-                }
-                if (keep_newlines) {
-                    eol = i;
-                }
-            }
-            lines.add(str.substring(j, eol));
-            j = i;
-        }
-        if (j < length) {
-            lines.add(str.substring(j, length));
-        }
-        return lines.toArray(new String[lines.size()]);
-    }
-        
     public static Object[] ll_split_chr(String str, char c) {
         ArrayList list = new ArrayList();
         int lastidx = 0, idx = 0;



More information about the Pypy-commit mailing list