Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

scripts/lib/abi/abi_parser.py: optimize parse_abi() function

Instead of using glob, use a recursive function to parse all files.

Such change reduces the total excecution time by 15% with my SSD disks.

Signed-off-by: Mauro Carvalho Chehab <mchehab+huawei@kernel.org>
Signed-off-by: Jonathan Corbet <corbet@lwn.net>
Link: https://lore.kernel.org/r/190dd358897017ed82c56f1e263192215ffbae43.1739182025.git.mchehab+huawei@kernel.org

authored by

Mauro Carvalho Chehab and committed by
Jonathan Corbet
c67c3fbd 9d7ec886

+38 -19
+38 -19
scripts/lib/abi/abi_parser.py
··· 12 12 import os 13 13 import re 14 14 15 - from glob import glob 16 15 from pprint import pformat 17 16 from random import randrange, seed 18 17 ··· 45 46 self.file_refs = {} 46 47 self.what_refs = {} 47 48 49 + # Ignore files that contain such suffixes 50 + self.ignore_suffixes = (".rej", ".org", ".orig", ".bak", "~") 51 + 48 52 # Regular expressions used on parser 53 + self.re_abi_dir = re.compile(r"(.*)" + ABI_DIR) 49 54 self.re_tag = re.compile(r"(\S+)(:\s*)(.*)", re.I) 50 55 self.re_valid = re.compile(self.TAGS) 51 56 self.re_start_spc = re.compile(r"(\s*)(\S.*)") ··· 325 322 for w in fdata.what: 326 323 self.add_symbol(what=w, fname=fname, xref=fdata.key) 327 324 328 - def parse_abi(self): 325 + def _parse_abi(self, root=None): 326 + """Internal function to parse documentation ABI recursively""" 327 + 328 + if not root: 329 + root = self.directory 330 + 331 + with os.scandir(root) as obj: 332 + for entry in obj: 333 + name = os.path.join(root, entry.name) 334 + 335 + if entry.is_dir(): 336 + self.parse_abi(name) 337 + continue 338 + 339 + if not entry.is_file(): 340 + continue 341 + 342 + basename = os.path.basename(name) 343 + 344 + if basename == "README": 345 + continue 346 + 347 + if basename.startswith("."): 348 + continue 349 + 350 + if basename.endswith(self.ignore_suffixes): 351 + continue 352 + 353 + path = self.re_abi_dir.sub("", os.path.dirname(name)) 354 + 355 + self.parse_file(name, path, basename) 356 + 357 + def parse_abi(self, root=None): 329 358 """Parse documentation ABI""" 330 359 331 - ignore_suffixes = ("rej", "org", "orig", "bak", "~") 332 - re_abi = re.compile(r".*" + ABI_DIR) 333 - 334 - for fname in glob(os.path.join(self.directory, "**"), recursive=True): 335 - if os.path.isdir(fname): 336 - continue 337 - 338 - basename = os.path.basename(fname) 339 - 340 - if basename == "README": 341 - continue 342 - if basename.startswith(".") or basename.endswith(ignore_suffixes): 343 - continue 344 - 345 - path = re_abi.sub("", os.path.dirname(fname)) 346 - 347 - self.parse_file(fname, path, basename) 360 + self._parse_abi(root) 348 361 349 362 if self.debug & AbiDebug.DUMP_ABI_STRUCTS: 350 363 self.log.debug(pformat(self.data))