From bd23c32d640fcbd9cfca70b2af8d7aef279299c5 Mon Sep 17 00:00:00 2001 From: Kunal Mehta Date: Sun, 26 Jul 2015 20:04:35 -0700 Subject: [PATCH] Optimize wmliterator.isDirective() Skips an unecessary for loop and if conditional. --- data/tools/wesnoth/wmliterator.py | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/data/tools/wesnoth/wmliterator.py b/data/tools/wesnoth/wmliterator.py index 6df3247f5eaa..00ded530d041 100644 --- a/data/tools/wesnoth/wmliterator.py +++ b/data/tools/wesnoth/wmliterator.py @@ -49,14 +49,13 @@ def wmlfindin(element, scopeElement, wmlItor): return itor return None + def isDirective(elem): "Identify things that shouldn't be indented." if isinstance(elem, WmlIterator): elem = elem.element - for prefix in ("#ifdef", "#ifndef", "#ifhave", "#ifnhave", "#ifver", "#ifnver", "#else", "#endif", "#define", "#enddef", "#undef"): - if elem.startswith(prefix): - return True - return False + return elem.startswith(("#ifdef", "#ifndef", "#ifhave", "#ifnhave", "#ifver", "#ifnver", "#else", "#endif", "#define", "#enddef", "#undef")) + def isCloser(elem): "Are we looking at a closing tag?"