Author: Maciej Fijalkowski <[email protected]>
Branch: optresult
Changeset: r77595:d0fb48169986
Date: 2015-05-26 20:02 +0200
http://bitbucket.org/pypy/pypy/changeset/d0fb48169986/

Log:    more hacking on vstring

diff --git a/rpython/jit/metainterp/optimizeopt/info.py 
b/rpython/jit/metainterp/optimizeopt/info.py
--- a/rpython/jit/metainterp/optimizeopt/info.py
+++ b/rpython/jit/metainterp/optimizeopt/info.py
@@ -330,6 +330,9 @@
     def _unpack_str(self, mode):
         return mode.hlstr(lltype.cast_opaque_ptr(
             lltype.Ptr(mode.LLTYPE), self._const.getref_base()))
+
+    def get_constant_string_spec(self, optforce, mode):
+        return self._unpack_str(mode)
     
     def getstrlen(self, op, string_optimizer, mode, ignored):
         return ConstInt(len(self._unpack_str(mode)))
diff --git a/rpython/jit/metainterp/optimizeopt/vstring.py 
b/rpython/jit/metainterp/optimizeopt/vstring.py
--- a/rpython/jit/metainterp/optimizeopt/vstring.py
+++ b/rpython/jit/metainterp/optimizeopt/vstring.py
@@ -68,9 +68,24 @@
                 self.lenbound = intutils.ConstIntBound(self.length)
         return self.lenbound
 
+    def get_constant_string_spec(self, string_optimizer, mode):
+        return None # can't be constant
+
     def force_box(self, op, optforce):
         if not self.is_virtual():
             return op
+        if self.mode is mode_string:
+            s = self.get_constant_string_spec(optforce, mode_string)
+            if s is not None:
+                c_s = get_const_ptr_for_string(s)
+                optforce.get_box_replacement(op).set_forwarded(c_s)
+                return
+        else:
+            s = self.get_constant_string_spec(optforce, mode_unicode)
+            if s is not None:
+                c_s = get_const_ptr_for_unicode(s)
+                optforce.get_box_replacement(op).set_forwarded(c_s)
+                return
         self._is_virtual = False
         lengthbox = self.getstrlen(op, optforce, self.mode, None)
         newop = ResOperation(self.mode.NEWSTR, [lengthbox])
@@ -190,6 +205,18 @@
             # ^^^ may still be None, if string_optimizer is None
         return self.lgtop
 
+    @specialize.arg(1)
+    def get_constant_string_spec(self, string_optimizer, mode):
+        ileft = string_optimizer.getptrinfo(self.vleft)
+        s1 = ileft.get_constant_string_spec(string_optimizer, mode)
+        if s1 is None:
+            return None
+        iright = string_optimizer.getptrinfo(self.vright)
+        s2 = iright.get_constant_string_spec(string_optimizer, mode)
+        if s2 is None:
+            return None
+        return s1 + s2
+
     def string_copy_parts(self, op, string_optimizer, targetbox, offsetbox,
                           mode):
         lefti = string_optimizer.getptrinfo(self.vleft)
_______________________________________________
pypy-commit mailing list
[email protected]
https://mail.python.org/mailman/listinfo/pypy-commit

Reply via email to