浏览代码

Caching crawling results for reuse across projects.

David Piuva 3 年之前
父节点
当前提交
53efc7e900
共有 1 个文件被更改,包括 19 次插入0 次删除
  1. 19 0
      Source/tools/builder/generator.cpp

+ 19 - 0
Source/tools/builder/generator.cpp

@@ -111,7 +111,26 @@ static void tokenize(List<String> &target, const ReadableString& line) {
 	flushToken(target, currentToken);
 	flushToken(target, currentToken);
 }
 }
 
 
+// When CACHED_ANALYSIS is enabled, files will only be analyzed once per session, by remembering them from previous projects.
+//   If features that require a different type of analysis per project are implemented, this can easily be turned off.
+#define CACHED_ANALYSIS
+
+#ifdef CACHED_ANALYSIS
+	// Remembering previous results from analyzing the same files.
+	List<Dependency> analysisCache;
+#endif
+
 void analyzeFile(Dependency &result, const ReadableString& absolutePath, Extension extension) {
 void analyzeFile(Dependency &result, const ReadableString& absolutePath, Extension extension) {
+	#ifdef CACHED_ANALYSIS
+		// Check if the file has already been analyzed.
+		for (int c = 0; c < analysisCache.length(); c++) {
+			if (string_match(analysisCache[c].path, absolutePath)) {
+				// Clone all the results to keep projects separate in memory for safety.
+				result = analysisCache[c];
+				return;
+			}
+		}
+	#endif
 	// Get the file's binary content.
 	// Get the file's binary content.
 	Buffer fileBuffer = file_loadBuffer(absolutePath);
 	Buffer fileBuffer = file_loadBuffer(absolutePath);
 	// Get the checksum
 	// Get the checksum