27.11.21 15:47, Jeremiah Vivian пише: > Many operations involving two literals are optimized (to a certain level). So > it sort of surprises me that literal comparisons are not optimized and > literal contains only convert the right operand to a constant if possible. > I'd like to implement optimizations for these especially for the literal > contains. There is a TODO in the ast optimizer for literal comparisons as > well, and that's another reason I would like to have these added.
Only these operations were optimized which were necessary or very useful. The Python parser produces only sign-less numbers, so it was necessary to optimize unary minus to make -5 as fast as 5. Binary plus and minus are necessary to make complex constants. "**" and "<<" are often used in expressions for limits, masks and flags (5*10**6, 2**32-1, 1<<12). There is a benefit of computing such constants at compile time. "*" and "/" can be used to create self-documenting constats too (24*60*60, 1/3). And finally, indexing of bytes objects gets an ASCII code of the character (b'a'[0]), it is useful too. _______________________________________________ Python-Dev mailing list -- python-dev@python.org To unsubscribe send an email to python-dev-le...@python.org https://mail.python.org/mailman3/lists/python-dev.python.org/ Message archived at https://mail.python.org/archives/list/python-dev@python.org/message/73G2WZDTKG57JKKUVOCFOIDEL3D75W4O/ Code of Conduct: http://python.org/psf/codeofconduct/