Use str.startswith() in python scripts.
Use the builtin startswith() string method instead of implementing it
manually.
diff --git a/tools/checkstack.py b/tools/checkstack.py
index 2fbc160..428c296 100755
--- a/tools/checkstack.py
+++ b/tools/checkstack.py
@@ -140,10 +140,10 @@
im = re_usestack.match(insn)
if im is not None:
- if insn[:5] == 'pushl' or insn[:6] == 'pushfl':
+ if insn.startswith('pushl') or insn.startswith('pushfl'):
stackusage += 4
continue
- elif insn[:5] == 'pushw' or insn[:6] == 'pushfw':
+ elif insn.startswith('pushw') or insn.startswith('pushfw'):
stackusage += 2
continue
stackusage += int(im.group('num'), 16)
@@ -158,13 +158,13 @@
insnaddr = m.group('insnaddr')
calladdr = m.group('calladdr')
if calladdr is None:
- if insn[:6] == 'lcallw':
+ if insn.startswith('lcallw'):
noteCall(cur, subfuncs, insnaddr, -1, stackusage + 4)
noteYield(cur, stackusage + 4)
- elif insn[:3] == 'int':
+ elif insn.startswith('int'):
noteCall(cur, subfuncs, insnaddr, -1, stackusage + 6)
noteYield(cur, stackusage + 6)
- elif insn[:3] == 'sti':
+ elif insn.startswith('sti'):
noteYield(cur, stackusage)
else:
# misc instruction
@@ -176,10 +176,10 @@
if '+' in ref:
# Inter-function jump.
pass
- elif insn[:1] == 'j':
+ elif insn.startswith('j'):
# Tail call
noteCall(cur, subfuncs, insnaddr, calladdr, 0)
- elif insn[:5] == 'calll':
+ elif insn.startswith('calll'):
noteCall(cur, subfuncs, insnaddr, calladdr, stackusage + 4)
else:
print "unknown call", ref