aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorNeil <nyamatongwe@gmail.com>2026-03-19 16:19:40 +1100
committerNeil <nyamatongwe@gmail.com>2026-03-19 16:19:40 +1100
commit7921b6660b76a6f3010d6ab081ab456409d7617a (patch)
treed4603416c7fff5ddaea4d60abaa3d9ce85c8b17a
parent69afca435b271b42a341730802467bacf88fa444 (diff)
downloadscintilla-mirror-7921b6660b76a6f3010d6ab081ab456409d7617a.tar.gz
Use functools.cache to add caching for FindPathToHeader. Simplify current cache.
Speeds up SciTE regeneration by better than 3x.
-rw-r--r--scripts/Dependencies.py30
1 files changed, 15 insertions, 15 deletions
diff --git a/scripts/Dependencies.py b/scripts/Dependencies.py
index 135c57ac8..51e332c56 100644
--- a/scripts/Dependencies.py
+++ b/scripts/Dependencies.py
@@ -17,9 +17,10 @@
# Only tested with ASCII file names.
# Copyright 2019 by Neil Hodgson <neilh@scintilla.org>
# The License.txt file describes the conditions under which this software may be distributed.
-# Requires Python 2.7 or later
+# Requires Python 3.6 or later
import codecs, glob, os, sys
+from functools import cache
if __name__ == "__main__":
import FileGenerator
@@ -28,6 +29,7 @@ else:
continuationLineEnd = " \\"
+@cache
def FindPathToHeader(header, includePath):
for incDir in includePath:
relPath = os.path.join(incDir, header)
@@ -35,27 +37,25 @@ def FindPathToHeader(header, includePath):
return relPath
return ""
-fhifCache = {} # Remember the includes in each file. ~5x speed up.
+@cache
def FindHeadersInFile(filePath):
- if filePath not in fhifCache:
- headers = []
- with codecs.open(filePath, "r", "utf-8") as f:
- for line in f:
- if line.strip().startswith("#include"):
- parts = line.split()
- if len(parts) > 1:
- header = parts[1]
- if header[0] != '<': # No system headers
- headers.append(header.strip('"'))
- fhifCache[filePath] = headers
- return fhifCache[filePath]
+ headers = []
+ with codecs.open(filePath, "r", "utf-8") as f:
+ for line in f:
+ if line.strip().startswith("#include"):
+ parts = line.split()
+ if len(parts) > 1:
+ header = parts[1]
+ if header[0] != '<': # No system headers
+ headers.append(header.strip('"'))
+ return headers
def FindHeadersInFileRecursive(filePath, includePath, renames):
headerPaths = []
for header in FindHeadersInFile(filePath):
if header in renames:
header = renames[header]
- relPath = FindPathToHeader(header, includePath)
+ relPath = FindPathToHeader(header, tuple(includePath))
if relPath and relPath not in headerPaths:
headerPaths.append(relPath)
subHeaders = FindHeadersInFileRecursive(relPath, includePath, renames)