J
Jason Smith
Hi. I just have a question about optimizations Python does when
converting to bytecode.
import re
for someString in someListOfStrings:
if re.match('foo', someString):
print someString, "matched!"
Does Python notice that re.match is called with the same expression, and
thus lift it out of the loop? Or do I need to always optimize by hand
using re.compile? I suspect so because the Python bytecode generator
would hardly know about a library function like re.compile, unlike e.g.
Perl, with builtin REs.
Thanks much for any clarification or advice.
--
Jason Smith
Open Enterprise Systems
Bangkok, Thailand
http://oes.co.th
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.4 (GNU/Linux)
Comment: Using GnuPG with Thunderbird - http://enigmail.mozdev.org
iD8DBQFA4VGMm5qEoSbpT3kRAsYpAKClQmFeamBfDx0vgTVpMc+utgmD/QCcDjpi
edwYF0cRA1V2BvlqV6y4/l4=
=YMB7
-----END PGP SIGNATURE-----
converting to bytecode.
import re
for someString in someListOfStrings:
if re.match('foo', someString):
print someString, "matched!"
Does Python notice that re.match is called with the same expression, and
thus lift it out of the loop? Or do I need to always optimize by hand
using re.compile? I suspect so because the Python bytecode generator
would hardly know about a library function like re.compile, unlike e.g.
Perl, with builtin REs.
Thanks much for any clarification or advice.
--
Jason Smith
Open Enterprise Systems
Bangkok, Thailand
http://oes.co.th
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.4 (GNU/Linux)
Comment: Using GnuPG with Thunderbird - http://enigmail.mozdev.org
iD8DBQFA4VGMm5qEoSbpT3kRAsYpAKClQmFeamBfDx0vgTVpMc+utgmD/QCcDjpi
edwYF0cRA1V2BvlqV6y4/l4=
=YMB7
-----END PGP SIGNATURE-----