[pypy-dev] [pypy-commit] pypy default: Optimize match.group('name') by making it a module dict.

Carl Friedrich Bolz cfbolz at gmx.de
Fri Jan 11 11:17:04 CET 2013


Hi Alex,

I don't really understand the first change of this commit. Why is it a
good idea to change the groupdict of the re parser to be a module dict?
There are supposed to be "not too many" module dicts, because they are
promoted on read. So I don't get why this is a sensible change.

Would you please add a comment to the point where the module dict is
instantiated why this is a good idea, and ideally also a test_pypy_c
test.

Cheers,

Carl Friedrich

On 01/05/2013 03:55 AM, alex_gaynor wrote:
> Author: Alex Gaynor <alex.gaynor at gmail.com>
> Branch:
> Changeset: r59708:3d2ff1e85bf5
> Date: 2013-01-04 18:55 -0800
> http://bitbucket.org/pypy/pypy/changeset/3d2ff1e85bf5/
>
> Log:	Optimize match.group('name') by making it a module dict.
>
> diff --git a/lib-python/2.7/sre_parse.py b/lib-python/2.7/sre_parse.py
> --- a/lib-python/2.7/sre_parse.py
> +++ b/lib-python/2.7/sre_parse.py
> @@ -16,6 +16,12 @@
>
>   from sre_constants import *
>
> +try:
> +    from __pypy__ import newdict
> +except ImportError:@
> +    def newdict(tp):
> +        return {}
> +
>   SPECIAL_CHARS = ".\\[{()*+?^$|"
>   REPEAT_CHARS = "*+?{"
>
> @@ -68,7 +74,7 @@
>           self.flags = 0
>           self.open = []
>           self.groups = 1
> -        self.groupdict = {}
> +        self.groupdict = newdict("module")
>       def opengroup(self, name=None):
>           gid = self.groups
>           self.groups = gid + 1
> 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
> @@ -90,7 +90,7 @@
>   # SRE_Pattern class
>
>   class W_SRE_Pattern(Wrappable):
> -    _immutable_fields_ = ["code", "flags", "num_groups"]
> +    _immutable_fields_ = ["code", "flags", "num_groups", "w_indexgroup"]
>
>       def cannot_copy_w(self):
>           space = self.space
> _______________________________________________
> pypy-commit mailing list
> pypy-commit at python.org
> http://mail.python.org/mailman/listinfo/pypy-commit
>



More information about the pypy-dev mailing list