cordova-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From agri...@apache.org
Subject [2/2] git commit: CB-5006 Add a cache in searchpath logic.
Date Thu, 27 Feb 2014 03:14:39 GMT
CB-5006 Add a cache in searchpath logic.

Sped up CCA: 5.3 -> 5.0 seconds.


Project: http://git-wip-us.apache.org/repos/asf/cordova-plugman/repo
Commit: http://git-wip-us.apache.org/repos/asf/cordova-plugman/commit/08ae8e0f
Tree: http://git-wip-us.apache.org/repos/asf/cordova-plugman/tree/08ae8e0f
Diff: http://git-wip-us.apache.org/repos/asf/cordova-plugman/diff/08ae8e0f

Branch: refs/heads/master
Commit: 08ae8e0f79f95abcf05be154a87d1b71f0fa92d8
Parents: b9d442d
Author: Andrew Grieve <agrieve@chromium.org>
Authored: Wed Feb 26 22:12:55 2014 -0500
Committer: Andrew Grieve <agrieve@chromium.org>
Committed: Wed Feb 26 22:12:55 2014 -0500

----------------------------------------------------------------------
 src/fetch.js | 32 +++++++++++++++++++++-----------
 1 file changed, 21 insertions(+), 11 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cordova-plugman/blob/08ae8e0f/src/fetch.js
----------------------------------------------------------------------
diff --git a/src/fetch.js b/src/fetch.js
index ca06852..13152f2 100644
--- a/src/fetch.js
+++ b/src/fetch.js
@@ -116,20 +116,30 @@ function checkID(expected_id, dir) {
     return dir;
 }
 
+var idCache = Object.create(null);
 // Look for plugin in local search path.
 function findLocalPlugin(plugin_id, searchpath) {
-    for(var i = 0; i < searchpath.length; i++){
-        var files = fs.readdirSync(searchpath[i]);
-        for (var j = 0; j < files.length; j++){
-            var plugin_path = path.join(searchpath[i], files[j]);
-            try {
-                var id = readId(plugin_path);
-                if (plugin_id === id) {
-                    return plugin_path;
-                }
+    function tryPath(p) {
+        if (!(p in idCache)) {
+            var id = null;
+            if (fs.existsSync(path.join(p, 'plugin.xml'))) {
+                id = readId(p);
             }
-            catch(err) {
-                require('../plugman').emit('verbose', 'Error while trying to read plugin.xml
from ' + plugin_path);
+            idCache[p] = id;
+        }
+        return (plugin_id === idCache[p]);
+    }
+
+    for (var i = 0; i < searchpath.length; i++) {
+        // Allow search path to point right to a plugin.
+        if (tryPath(searchpath[i])) {
+            return searchpath[i];
+        }
+        var files = fs.readdirSync(searchpath[i]);
+        for (var j = 0; j < files.length; j++) {
+            var pluginPath = path.join(searchpath[i], files[j]);
+            if (tryPath(pluginPath)) {
+                return pluginPath;
             }
         }
     }


Mime
View raw message