[pypy-dev] [pypy-commit] pypy default: make looking up encodings free with the JIT

Carl Friedrich Bolz cfbolz at gmx.de
Wed Apr 10 14:55:21 CEST 2013


Hi Alex, 

I agree with Anto. Also, this has happened a few times now :-). I know that it's inconvenient to do a local translation or a branch. Can we think of another way to make this less annoying/prevent it from being forgotten? 

Cheers, 

Carl Friedrich 

Antonio Cuni <anto.cuni at gmail.com> wrote:

>Hi Alex,
>
>could we have a test_pypy_c test for this please?
>
>On 10/04/13 03:53, alex_gaynor wrote:
>> Author: Alex Gaynor <alex.gaynor at gmail.com>
>> Branch:
>> Changeset: r63186:c514bbc4c086
>> Date: 2013-04-09 19:53 -0700
>> http://bitbucket.org/pypy/pypy/changeset/c514bbc4c086/
>>
>> Log:	make looking up encodings free with the JIT
>>
>> diff --git a/pypy/module/_codecs/interp_codecs.py
>b/pypy/module/_codecs/interp_codecs.py
>> --- a/pypy/module/_codecs/interp_codecs.py
>> +++ b/pypy/module/_codecs/interp_codecs.py
>> @@ -1,10 +1,18 @@
>> +from rpython.rlib import jit
>> +from rpython.rlib.objectmodel import we_are_translated
>> +from rpython.rlib.rstring import UnicodeBuilder
>> +
>>   from pypy.interpreter.error import OperationError, operationerrfmt
>>   from pypy.interpreter.gateway import interp2app, unwrap_spec,
>WrappedDefault
>> -from rpython.rlib.rstring import UnicodeBuilder
>> -from rpython.rlib.objectmodel import we_are_translated
>> +
>> +
>> +class VersionTag(object):
>> +    pass
>>
>>
>>   class CodecState(object):
>> +    _immutable_fields_ = ["version?"]
>> +
>>       def __init__(self, space):
>>           self.codec_search_path = []
>>           self.codec_search_cache = {}
>> @@ -14,6 +22,7 @@
>>           self.encode_error_handler =
>self.make_encode_errorhandler(space)
>>
>>           self.unicodedata_handler = None
>> +        self.modified()
>>
>>       def _make_errorhandler(self, space, decode):
>>           def call_errorhandler(errors, encoding, reason, input,
>startpos,
>> @@ -86,9 +95,20 @@
>>               self.unicodedata_handler = UnicodeData_Handler(space,
>w_getcode)
>>               return self.unicodedata_handler
>>
>> +    def modified(self):
>> +        self.version = VersionTag()
>> +
>> +    def get_codec_from_cache(self, key):
>> +        return self._get_codec_with_version(key, self.version)
>> +
>> +    @jit.elidable
>> +    def _get_codec_with_version(self, key, version):
>> +        return self.codec_search_cache.get(key, None)
>> +
>>       def _cleanup_(self):
>>           assert not self.codec_search_path
>>
>> +
>>   def register_codec(space, w_search_function):
>>       """register(search_function)
>>
>> @@ -115,11 +135,12 @@
>>           "lookup_codec() should not be called during translation"
>>       state = space.fromcache(CodecState)
>>       normalized_encoding = encoding.replace(" ", "-").lower()
>> -    w_result = state.codec_search_cache.get(normalized_encoding,
>None)
>> +    w_result = state.get_codec_from_cache(normalized_encoding)
>>       if w_result is not None:
>>           return w_result
>>       return _lookup_codec_loop(space, encoding, normalized_encoding)
>>
>> +
>>   def _lookup_codec_loop(space, encoding, normalized_encoding):
>>       state = space.fromcache(CodecState)
>>       if state.codec_need_encodings:
>> @@ -143,6 +164,7 @@
>>                       space.wrap("codec search functions must return
>4-tuples"))
>>               else:
>>                   state.codec_search_cache[normalized_encoding] =
>w_result
>> +                state.modified()
>>                   return w_result
>>       raise operationerrfmt(
>>           space.w_LookupError,
>> _______________________________________________
>> pypy-commit mailing list
>> pypy-commit at python.org
>> http://mail.python.org/mailman/listinfo/pypy-commit
>>
>	
>_______________________________________________
>pypy-dev mailing list
>pypy-dev at python.org
>http://mail.python.org/mailman/listinfo/pypy-dev
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/pypy-dev/attachments/20130410/cdb562a8/attachment.html>


More information about the pypy-dev mailing list