Author: Armin Rigo <ar...@tunes.org> Branch: unicode-utf8-re Changeset: r93339:ebe0641d78a5 Date: 2017-12-09 20:44 +0100 http://bitbucket.org/pypy/pypy/changeset/ebe0641d78a5/
Log: Must not call ctx.next() when the type of ctx is not exactly known. Workaround for interp_sre, where the few calls are not performance- sensitive. diff --git a/pypy/module/_sre/interp_sre.py b/pypy/module/_sre/interp_sre.py --- a/pypy/module/_sre/interp_sre.py +++ b/pypy/module/_sre/interp_sre.py @@ -198,7 +198,7 @@ matchlist_w.append(w_item) reset_at = ctx.match_end if ctx.match_start == ctx.match_end: - reset_at = ctx.next(reset_at) + reset_at = ctx.next_indirect(reset_at) ctx.reset(reset_at) return space.newlist(matchlist_w) @@ -223,7 +223,7 @@ if ctx.match_start == ctx.match_end: # zero-width match if ctx.match_start == ctx.end: # or end of string break - ctx.reset(ctx.next(ctx.match_end)) + ctx.reset(ctx.next_indirect(ctx.match_end)) continue splitlist.append(slice_w(space, ctx, last, ctx.match_start, space.w_None)) @@ -320,7 +320,7 @@ strbuilder, last_pos, ctx.match_start) start = ctx.match_end if start == ctx.match_start: - start = ctx.next(start) + start = ctx.next_indirect(start) if not (last_pos == ctx.match_start == ctx.match_end and n > 0): # the above ignores empty matches on latest position @@ -682,13 +682,13 @@ ctx = self.ctx nextstart = ctx.match_end if ctx.match_start == nextstart: - nextstart = ctx.next(nextstart) + nextstart = ctx.next_indirect(nextstart) self.ctx = ctx.fresh_copy(nextstart) match = W_SRE_Match(self.srepat, ctx) return match else: # obscure corner case - self.ctx.match_start = self.ctx.next(self.ctx.match_start) + self.ctx.match_start = self.ctx.next_indirect(self.ctx.match_start) return None W_SRE_Scanner.typedef = TypeDef( diff --git a/rpython/rlib/rsre/rsre_core.py b/rpython/rlib/rsre/rsre_core.py --- a/rpython/rlib/rsre/rsre_core.py +++ b/rpython/rlib/rsre/rsre_core.py @@ -172,6 +172,8 @@ return position1 - position2 def go_forward_by_bytes(self, base_position, index): return base_position + index + def next_indirect(self, position): + return position + 1 # like next(), but can be called indirectly def get_mark(self, gid): return find_mark(self.match_marks, gid) diff --git a/rpython/rlib/rsre/rsre_utf8.py b/rpython/rlib/rsre/rsre_utf8.py --- a/rpython/rlib/rsre/rsre_utf8.py +++ b/rpython/rlib/rsre/rsre_utf8.py @@ -34,6 +34,7 @@ def next(self, position): return rutf8.next_codepoint_pos(self._utf8, position) + next_indirect = next def prev(self, position): if position <= 0: diff --git a/rpython/rlib/rsre/test/support.py b/rpython/rlib/rsre/test/support.py --- a/rpython/rlib/rsre/test/support.py +++ b/rpython/rlib/rsre/test/support.py @@ -29,6 +29,7 @@ def next(self, position): assert isinstance(position, Position) return Position(position._p + 1) + next_indirect = next def prev(self, position): assert isinstance(position, Position) _______________________________________________ pypy-commit mailing list pypy-commit@python.org https://mail.python.org/mailman/listinfo/pypy-commit