Author: Carl Friedrich Bolz <cfb...@gmx.de> Branch: Changeset: r86954:4753c209847a Date: 2016-09-08 13:54 +0200 http://bitbucket.org/pypy/pypy/changeset/4753c209847a/
Log: build the hashmap only once, not *every time* we call _has_reflected_op (found while reading control flow graphs) diff --git a/pypy/module/micronumpy/ufuncs.py b/pypy/module/micronumpy/ufuncs.py --- a/pypy/module/micronumpy/ufuncs.py +++ b/pypy/module/micronumpy/ufuncs.py @@ -392,31 +392,39 @@ extobj_w = space.newlist([space.wrap(8192), space.wrap(0), space.w_None]) return extobj_w + +_reflected_ops = { + 'add': 'radd', + 'subtract': 'rsub', + 'multiply': 'rmul', + 'divide': 'rdiv', + 'true_divide': 'rtruediv', + 'floor_divide': 'rfloordiv', + 'remainder': 'rmod', + 'power': 'rpow', + 'left_shift': 'rlshift', + 'right_shift': 'rrshift', + 'bitwise_and': 'rand', + 'bitwise_xor': 'rxor', + 'bitwise_or': 'ror', + #/* Comparisons */ + 'equal': 'eq', + 'not_equal': 'ne', + 'greater': 'lt', + 'less': 'gt', + 'greater_equal': 'le', + 'less_equal': 'ge', +} + +for key, value in _reflected_ops.items(): + _reflected_ops[key] = "__" + value + "__" +del key +del value + def _has_reflected_op(space, w_obj, op): - refops ={ 'add': 'radd', - 'subtract': 'rsub', - 'multiply': 'rmul', - 'divide': 'rdiv', - 'true_divide': 'rtruediv', - 'floor_divide': 'rfloordiv', - 'remainder': 'rmod', - 'power': 'rpow', - 'left_shift': 'rlshift', - 'right_shift': 'rrshift', - 'bitwise_and': 'rand', - 'bitwise_xor': 'rxor', - 'bitwise_or': 'ror', - #/* Comparisons */ - 'equal': 'eq', - 'not_equal': 'ne', - 'greater': 'lt', - 'less': 'gt', - 'greater_equal': 'le', - 'less_equal': 'ge', - } - if op not in refops: + if op not in _reflected_ops: return False - return space.getattr(w_obj, space.wrap('__' + refops[op] + '__')) is not None + return space.getattr(w_obj, space.wrap(_reflected_ops[op])) is not None def safe_casting_mode(casting): assert casting is not None _______________________________________________ pypy-commit mailing list pypy-commit@python.org https://mail.python.org/mailman/listinfo/pypy-commit