Use str.startswith() in python scripts.
Use the builtin startswith() string method instead of implementing it
manually.
diff --git a/tools/layoutrom.py b/tools/layoutrom.py
index 5f8c368..7603f38 100755
--- a/tools/layoutrom.py
+++ b/tools/layoutrom.py
@@ -59,10 +59,9 @@
# Return the subset of sections with a given name prefix
def getSectionsPrefix(sections, prefix):
- lp = len(prefix)
out = []
for size, align, name in sections:
- if name[:lp] == prefix:
+ if name.startswith(prefix):
out.append((size, align, name))
return out
@@ -79,7 +78,7 @@
fixedsections = []
for sectioninfo in sections:
size, align, name = sectioninfo
- if name[:11] == '.fixedaddr.':
+ if name.startswith('.fixedaddr.'):
addr = int(name[11:], 16)
fixedsections.append((addr, sectioninfo))
if align != 1:
@@ -295,7 +294,7 @@
# Find and keep the section associated with a symbol (if available).
def keepsymbol(symbol, infos, pos, callerpos=None):
addr, section = infos[pos][1].get(symbol, (None, None))
- if section is None or '*' in section or section[:9] == '.discard.':
+ if section is None or '*' in section or section.startswith('.discard.'):
return -1
if callerpos is not None and symbol not in infos[callerpos][4]:
# This symbol reference is a cross section reference (an xref).
@@ -340,7 +339,7 @@
(info32flat[0], info32flat[1], info32flat[2], [], {}))
# Start by keeping sections that are globally visible.
for size, align, section in info16[0]:
- if section[:11] == '.fixedaddr.' or '.export.' in section:
+ if section.startswith('.fixedaddr.') or '.export.' in section:
keepsection(section, infos)
keepsymbol('post32', infos, 0, 2)
# Return sections found.
@@ -372,7 +371,7 @@
if line == 'SYMBOL TABLE:':
state = 'symbol'
continue
- if line[:24] == 'RELOCATION RECORDS FOR [':
+ if line.startswith('RELOCATION RECORDS FOR ['):
state = 'reloc'
relocsection = line[24:-2]
continue