From bb3396bb39cbfe75f4d93073f2336c9dff1ccd91 Mon Sep 17 00:00:00 2001 From: Frerich Raabe Date: Wed, 24 Aug 2016 11:26:01 +0200 Subject: [PATCH 1/3] Avoid unneeded list in ManifestRepository.getIncludesContentHashForFiles The 'listOfIncludeHashes' list was only used to get a list of the hashes of the contents of all include files. However, we already have this list: the given 'includes' dictionary has the hashes of all include files as the values, and by the time we get to the end of 'listOfIncludeHashes' we already verified that all the include files exist and they still have the same hashes. --- clcache.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/clcache.py b/clcache.py index ca6cc976..4f57c60b 100644 --- a/clcache.py +++ b/clcache.py @@ -193,7 +193,6 @@ def getManifestHash(compilerBinary, commandLine, sourceFile): @staticmethod def getIncludesContentHashForFiles(includes): - listOfIncludesHashes = [] includeMissing = False for path in sorted(includes.keys()): @@ -201,14 +200,13 @@ def getIncludesContentHashForFiles(includes): fileHash = getFileHash(path) if fileHash != includes[path]: raise IncludeChangedException() - listOfIncludesHashes.append(fileHash) except FileNotFoundError: includeMissing = True if includeMissing: raise IncludeNotFoundException() - return ManifestRepository.getIncludesContentHashForHashes(listOfIncludesHashes) + return ManifestRepository.getIncludesContentHashForHashes(sorted(includes.values())) @staticmethod def getIncludesContentHashForHashes(listOfIncludesHashes): From 6e5596a8abad0eb610e26c82530e54491b91c457 Mon Sep 17 00:00:00 2001 From: Frerich Raabe Date: Wed, 24 Aug 2016 12:00:29 +0200 Subject: [PATCH 2/3] Factored-out verification of includes mentioned in manifest This patch moves the code for verifying that the list of includes (and the hash code of the include file contents) is accurate into a separate function. The reason for this is that I think that not all users of ManifestRepository.getIncludesContentHashForFiles() need this functionality... --- clcache.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/clcache.py b/clcache.py index 4f57c60b..91aafa90 100644 --- a/clcache.py +++ b/clcache.py @@ -192,7 +192,7 @@ def getManifestHash(compilerBinary, commandLine, sourceFile): return getFileHash(sourceFile, additionalData) @staticmethod - def getIncludesContentHashForFiles(includes): + def verifyIncludesHashes(includes): includeMissing = False for path in sorted(includes.keys()): @@ -206,6 +206,9 @@ def getIncludesContentHashForFiles(includes): if includeMissing: raise IncludeNotFoundException() + @staticmethod + def getIncludesContentHashForFiles(includes): + ManifestRepository.verifyIncludesHashes(includes) return ManifestRepository.getIncludesContentHashForHashes(sorted(includes.values())) @staticmethod From 49b0bbfa8df5dffc545c2dba666a2c685a0a8823 Mon Sep 17 00:00:00 2001 From: Frerich Raabe Date: Wed, 24 Aug 2016 12:02:36 +0200 Subject: [PATCH 3/3] Optimized creating manifests When creating manifests, we would first compute the list of included files, then commpute the hash code of their contents and then call ManifestRepository.getIncludesContentHashForFiles(). That function would then re-compute the file hash for each file to see whether it's still the same, but there's no point in doing so since we just computed the hash! --- clcache.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/clcache.py b/clcache.py index 91aafa90..cc1bfc02 100644 --- a/clcache.py +++ b/clcache.py @@ -208,7 +208,6 @@ def verifyIncludesHashes(includes): @staticmethod def getIncludesContentHashForFiles(includes): - ManifestRepository.verifyIncludesHashes(includes) return ManifestRepository.getIncludesContentHashForHashes(sorted(includes.values())) @staticmethod @@ -1515,10 +1514,12 @@ def processDirect(cache, objectFile, compiler, cmdLine, sourceFile): if manifest is not None: # NOTE: command line options already included in hash for manifest name try: - includesContentHash = ManifestRepository.getIncludesContentHashForFiles({ + includes = { expandBasedirPlaceholder(path, baseDir):contentHash for path, contentHash in manifest.includeFiles.items() - }) + } + ManifestRepository.verifyIncludesHashes(includes) + includesContentHash = ManifestRepository.getIncludesContentHashForFiles(includes) cachekey = manifest.includesContentToObjectMap.get(includesContentHash) assert cachekey is not None