提交 94ee7a57 authored 作者: Olivier Delalleau's avatar Olivier Delalleau

Safer string comparison

Comparing strings with 'is' is dangerous, as there is no guarantee that Python will store similar strings into the same memory space.
上级 c0c02aa4
......@@ -63,12 +63,14 @@ _optimizer_specialize = compile.optdb.query(_optimizer_specialize)
_optimizer_fast_run = gof.Query(include=['fast_run'])
_optimizer_fast_run = compile.optdb.query(_optimizer_fast_run)
def optimize(g, level='fast_run'):
if 'fast_run' is level:
if level == 'fast_run':
_optimizer_fast_run.optimize(g)
elif 'specialize' is level:
elif level == 'specialize':
_optimizer_specialize.optimize(g)
elif 'stabilize' is level:
elif level == 'stabilize':
_optimizer_stabilize.optimize(g)
else:
raise ValueError(level)
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论