gen_compile_commands: parse only the first line of .*.cmd files

After the allmodconfig build, this script takes about 5 sec on my
machine. Most of the run-time is consumed for needless regex matching.

We know the format of .*.cmd file; the first line is the build command.
There is no need to parse the rest.

With this optimization, now it runs 4 times faster.

Signed-off-by: Masahiro Yamada <masahiroy@kernel.org>
Reviewed-by: Nick Desaulniers <ndesaulniers@google.com>
Tested-by: Nick Desaulniers <ndesaulniers@google.com>
This commit is contained in:
Masahiro Yamada 2020-08-22 23:56:09 +09:00
parent 23cd88c913
commit 8a685db32f

View File

@ -125,11 +125,8 @@ def main():
filepath = os.path.join(dirpath, filename)
with open(filepath, 'rt') as f:
for line in f:
result = line_matcher.match(line)
if not result:
continue
result = line_matcher.match(f.readline())
if result:
try:
entry = process_line(directory, dirpath,
result.group(1), result.group(2))