Author: Lukas Diekmann <[email protected]>
Branch: list-strategies
Changeset: r47535:5907a41f5c7b
Date: 2011-09-06 13:11 +0200
http://bitbucket.org/pypy/pypy/changeset/5907a41f5c7b/

Log:    added stringsorter class to compare strings faster

diff --git a/pypy/objspace/std/listobject.py b/pypy/objspace/std/listobject.py
--- a/pypy/objspace/std/listobject.py
+++ b/pypy/objspace/std/listobject.py
@@ -1168,6 +1168,14 @@
         space = self.space
         return w_int1.intval < w_int2.intval
 
+class StringSort(SimpleSort):
+    def lt(self, w_str1, w_str2):
+        from pypy.objspace.std.intobject import W_StringObject
+        assert isinstance(w_int1, W_StringObject)
+        assert isinstance(w_int2, W_StringObject)
+        space = self.space
+        return w_str1._value < w_str2._value
+
 class CustomCompareSort(SimpleSort):
     def lt(self, a, b):
         space = self.space
@@ -1214,6 +1222,8 @@
         else:
             if w_list.strategy is space.fromcache(IntegerListStrategy):
                 sorterclass = IntSort
+            elif w_list.strategy is space.fromcache(StringListStrategy):
+                sorterclass = StringSort
             else:
                 sorterclass = SimpleSort
     #XXX optimize this, getitems is bad
_______________________________________________
pypy-commit mailing list
[email protected]
http://mail.python.org/mailman/listinfo/pypy-commit

Reply via email to