Skip to content

Commit 99b39a6

Browse files
committed
Optimize llvm-nm for single file, skip complex parsing
1 parent 34ae9a9 commit 99b39a6

File tree

1 file changed

+24
-16
lines changed

1 file changed

+24
-16
lines changed

tools/building.py

Lines changed: 24 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -390,28 +390,36 @@ def llvm_nm_multiple(files):
390390
# for each individual file.
391391

392392
filename = llvm_nm_files[0]
393-
file_start = 0
394-
i = 0
395-
396-
while True:
397-
nl = results.find('\n', i)
398-
if nl < 0:
399-
break
400-
colon = results.rfind(':', i, nl)
401-
if colon >= 0 and results[colon + 1] == '\n': # New file start?
402-
nm_cache[filename] = parse_symbols(results[file_start:i - 1])
403-
filename = results[i:colon].strip()
404-
file_start = colon + 2
405-
i = nl + 1
406-
407-
nm_cache[filename] = parse_symbols(results[file_start:])
393+
394+
# When we dispatched more than one file, we must manually parse
395+
# the file result delimiters (like shown structured above)
396+
if len(llvm_nm_files) > 1:
397+
file_start = 0
398+
i = 0
399+
400+
while True:
401+
nl = results.find('\n', i)
402+
if nl < 0:
403+
break
404+
colon = results.rfind(':', i, nl)
405+
if colon >= 0 and results[colon + 1] == '\n': # New file start?
406+
nm_cache[filename] = parse_symbols(results[file_start:i - 1])
407+
filename = results[i:colon].strip()
408+
file_start = colon + 2
409+
i = nl + 1
410+
411+
nm_cache[filename] = parse_symbols(results[file_start:])
412+
else:
413+
# We only dispatched a single file, we can just parse that directly
414+
# to the output.
415+
nm_cache[filename] = parse_symbols(results)
408416

409417
# Any files that failed llvm-nm (e.g. they did not have any
410418
# symbols) will be not present in the above, so fill in dummies
411419
# for those.
412420
for f in files:
413421
if f not in nm_cache:
414-
nm_cache[f] = ObjectFileInfo(1, '')
422+
nm_cache[f] = llvm_nm(f)
415423

416424
return [nm_cache[f] for f in files]
417425

0 commit comments

Comments
 (0)