>>> - frozenset("ab") | frozenset("bc") => frozenset("abc") > > That's a name lookup, too.
Yes, and it is only optimized if the "builtin_funcs" feature is enabled explictly. > Except that evaluating something like '"abc" * constant' can eat up all > memory, imagine this code: > > KILL_MEMORY = sys.argv[1] == 'NEVER PASS THIS VALUE' > > def test(): > if KILL_MEMORY: > return 'abc' * 10000000000000000000000000000 > else: > return 'abc' The optimizer always check the result of an optimization for constraints. For example, an optimization is cancelled if the result is not immutable. Integers must be in the range [-2^128; 2^128-1] by default. Strings are limited to 4096 bytes/characters. Tuples are limited to 20 items. The compiler may waste some seconds to evaluate an expression and then drop the result, but I don't really care right now. I prefer to spend minutes to compile if the application is faster at runtime. astoptimizer tries to avoid expensive operations when it knows that the result will be too big. For your specific example, str * int is *not* evulated if the result will be longer than the limit. Similar sanity checks may be added later for pow(int, int) and math.factorial(int) for example. Victor _______________________________________________ Python-Dev mailing list Python-Dev@python.org http://mail.python.org/mailman/listinfo/python-dev Unsubscribe: http://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com