[pypy-svn] r16938 - pypy/release/0.7.x/pypy/module/_sre

nik at codespeak.net nik at codespeak.net
Sun Aug 28 10:54:53 CEST 2005


Author: nik
Date: Sun Aug 28 10:54:52 2005
New Revision: 16938

Modified:
   pypy/release/0.7.x/pypy/module/_sre/interp_sre.py
Log:
converting regex bytecodes to integers before interpretation, even if they're
longs


Modified: pypy/release/0.7.x/pypy/module/_sre/interp_sre.py
==============================================================================
--- pypy/release/0.7.x/pypy/module/_sre/interp_sre.py	(original)
+++ pypy/release/0.7.x/pypy/module/_sre/interp_sre.py	Sun Aug 28 10:54:52 2005
@@ -207,9 +207,6 @@
         return self.state.end - self.string_position
 
     def peek_code(self, peek=0):
-        return intmask(self.pattern_codes[self.code_position + peek])
-
-    def peek_code_uint(self, peek=0):
         return self.pattern_codes[self.code_position + peek]
 
     def skip_code(self, skip_count):
@@ -254,19 +251,19 @@
 
 def w_search(space, w_state, w_pattern_codes):
     assert isinstance(w_state, W_State)
-    pattern_codes = [space.uint_w(code) for code
+    pattern_codes = [intmask(space.uint_w(code)) for code
                                     in space.unpackiterable(w_pattern_codes)]
     return space.newbool(search(space, w_state, pattern_codes))
 
 def search(space, state, pattern_codes):
     flags = 0
-    if intmask(pattern_codes[0]) == OPCODE_INFO:
+    if pattern_codes[0] == OPCODE_INFO:
         # optimization info block
         # <INFO> <1=skip> <2=flags> <3=min> <4=max> <5=prefix info>
-        if intmask(pattern_codes[2]) & SRE_INFO_PREFIX and intmask(pattern_codes[5]) > 1:
+        if pattern_codes[2] & SRE_INFO_PREFIX and pattern_codes[5] > 1:
             return fast_search(space, state, pattern_codes)
-        flags = intmask(pattern_codes[2])
-        offset = intmask(pattern_codes[1]) + 1
+        flags = pattern_codes[2]
+        offset = pattern_codes[1] + 1
         assert offset >= 0
         pattern_codes = pattern_codes[offset:]
 
@@ -284,18 +281,18 @@
     an optimization info block."""
     # pattern starts with a known prefix
     # <5=length> <6=skip> <7=prefix data> <overlap data>
-    flags = intmask(pattern_codes[2])
-    prefix_len = intmask(pattern_codes[5])
+    flags = pattern_codes[2]
+    prefix_len = pattern_codes[5]
     assert prefix_len >= 0
-    prefix_skip = intmask(pattern_codes[6]) # don't really know what this is good for
+    prefix_skip = pattern_codes[6] # don't really know what this is good for
     assert prefix_skip >= 0
     prefix = pattern_codes[7:7 + prefix_len]
     overlap_offset = 7 + prefix_len - 1
-    overlap_stop = intmask(pattern_codes[1]) + 1
+    overlap_stop = pattern_codes[1] + 1
     assert overlap_offset >= 0
     assert overlap_stop >= 0
     overlap = pattern_codes[overlap_offset:overlap_stop]
-    pattern_offset = intmask(pattern_codes[1]) + 1
+    pattern_offset = pattern_codes[1] + 1
     assert pattern_offset >= 0
     pattern_codes = pattern_codes[pattern_offset:]
     i = 0
@@ -304,11 +301,11 @@
         while True:
             char_ord = space.int_w(space.ord(
                 space.getitem(state.w_string, space.wrap(string_position))))
-            if char_ord != intmask(prefix[i]):
+            if char_ord != prefix[i]:
                 if i == 0:
                     break
                 else:
-                    i = intmask(overlap[i])
+                    i = overlap[i]
             else:
                 i += 1
                 if i == prefix_len:
@@ -320,22 +317,22 @@
                         return True # matched all of pure literal pattern
                     if match(space, state, pattern_codes[2 * prefix_skip:]):
                         return True
-                    i = intmask(overlap[i])
+                    i = overlap[i]
                 break
         string_position += 1
     return False
 
 def w_match(space, w_state, w_pattern_codes):
     assert isinstance(w_state, W_State)
-    pattern_codes = [space.uint_w(code) for code
+    pattern_codes = [intmask(space.uint_w(code)) for code
                                     in space.unpackiterable(w_pattern_codes)]
     return space.newbool(match(space, w_state, pattern_codes))
 
 def match(space, state, pattern_codes):
     # Optimization: Check string length. pattern_codes[3] contains the
     # minimum length for a string to possibly match.
-    if intmask(pattern_codes[0]) == OPCODE_INFO and intmask(pattern_codes[3]) > 0:
-        if state.end - state.string_position < intmask(pattern_codes[3]):
+    if pattern_codes[0] == OPCODE_INFO and pattern_codes[3] > 0:
+        if state.end - state.string_position < pattern_codes[3]:
             return False
     state.context_stack.append(MatchContext(space, state, pattern_codes))
     has_matched = MatchContext.UNDECIDED
@@ -1164,7 +1161,7 @@
             shift = 4
         else:
             shift = 5
-        block_value = ctx.peek_code_uint(block * (32 / CODESIZE)
+        block_value = ctx.peek_code(block * (32 / CODESIZE)
                                                 + ((char_code & 255) >> shift))
         if block_value & (1 << (char_code & ((8 * CODESIZE) - 1))):
             return ctx.set_ok



More information about the Pypy-commit mailing list