Skip to content

Commit 4d2e76b

Browse files
authored
Optimize quadratic test_dwarf down to linear. (#25056)
Optimize quadratic test_dwarf down to linear. Speeds up lsan.test_dwarf down from 476 seconds to 1.7 seconds.
1 parent 4aa1f81 commit 4d2e76b

File tree

1 file changed

+10
-14
lines changed

1 file changed

+10
-14
lines changed

test/test_core.py

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -7952,24 +7952,20 @@ def test_dwarf(self):
79527952

79537953
# parse the sections
79547954
sections = {}
7955-
curr_section_name = ''
7956-
curr_section_body = ''
79577955

7958-
def add_section():
7959-
if curr_section_name:
7960-
sections[curr_section_name] = curr_section_body
7956+
lines = out.splitlines()
7957+
# Add a sentinel to ensure the last section gets flushed properly
7958+
lines += [' dummy contents:']
79617959

7962-
for line in out.splitlines():
7960+
curr_section_name = ''
7961+
curr_section_start = -1
7962+
for i, line in enumerate(lines):
79637963
if ' contents:' in line:
7964-
# a new section, a line like ".debug_str contents:"
7965-
add_section()
7964+
if curr_section_start >= 0:
7965+
# a new section, a line like ".debug_str contents:"
7966+
sections[curr_section_name] = '\n'.join(lines[curr_section_start:i])
79667967
curr_section_name = line.split(' ')[0]
7967-
curr_section_body = ''
7968-
else:
7969-
# possibly a line in a section
7970-
if curr_section_name:
7971-
curr_section_body += line + '\n'
7972-
add_section()
7968+
curr_section_start = i + 1
79737969

79747970
# make sure the right sections exist
79757971
self.assertIn('.debug_abbrev', sections)

0 commit comments

Comments
 (0)