[gimp] tools: in performance-log-viewer.py, cache source file lookups



commit 97498017c098f136ece121b3c6b208e5e33553b5
Author: Ell <ell_se yahoo com>
Date:   Sun Sep 30 05:34:59 2018 -0400

    tools: in performance-log-viewer.py, cache source file lookups
    
    In the performance-log viewer, cache the results of source-file
    lookups, to speed up future lookups.

 tools/performance-log-viewer.py | 36 ++++++++++++++++++++++--------------
 1 file changed, 22 insertions(+), 14 deletions(-)
---
diff --git a/tools/performance-log-viewer.py b/tools/performance-log-viewer.py
index ab80089bf9..6f8d73d756 100755
--- a/tools/performance-log-viewer.py
+++ b/tools/performance-log-viewer.py
@@ -82,28 +82,36 @@ editor_command  = os.environ.get ("PERFORMANCE_LOG_VIEWER_EDITOR",
 editor_command += " &"
 
 def find_file (filename):
-    filename = re.sub ("[\\\\/]", GLib.DIR_SEPARATOR_S, filename)
+    def lookup (filename):
+        filename = re.sub ("[\\\\/]", GLib.DIR_SEPARATOR_S, filename)
 
-    if GLib.path_is_absolute (filename):
-        file = Gio.File.new_for_path (filename)
+        if GLib.path_is_absolute (filename):
+            file = Gio.File.new_for_path (filename)
 
-        if file.query_exists ():
-            return file
+            if file.query_exists ():
+                return file
 
-    for path in search_path:
-        rest = filename
+        for path in search_path:
+            rest = filename
 
-        while rest:
-            file = Gio.File.new_for_path (GLib.build_filenamev ((path, rest)))
+            while rest:
+                file = Gio.File.new_for_path (GLib.build_filenamev ((path, rest)))
 
-            if file.query_exists ():
-                return file
+                if file.query_exists ():
+                    return file
+
+                sep = rest.find (GLib.DIR_SEPARATOR_S)
+
+                rest = rest[sep + 1:] if sep >= 0 else ""
+
+        return None
 
-            sep = rest.find (GLib.DIR_SEPARATOR_S)
+    if filename not in find_file.cache:
+        find_file.cache[filename] = lookup (filename)
 
-            rest = rest[sep + 1:] if sep >= 0 else ""
+    return find_file.cache[filename]
 
-    return None
+find_file.cache = {}
 
 VariableType = namedtuple ("VariableType",
                            ("parse", "format", "format_numeric"))


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]