Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

PATCH: autoloading already loaded features



On Sat, 9 Nov 2013 22:32:50 +0000
Peter Stephenson <p.w.stephenson@xxxxxxxxxxxx> wrote:
> For autoloads from modules, which may be builtins, conditions, math
> functions or parameters, we can actually do a bit better, with a little
> more work but nothing like to the same extent (no additional loading is
> required).  Suppose we load builtin bar from zsh/foo at some point,
> doesn't matter how, then run "zmodload -a bar zsh/foo".  We find that a
> builtin bar exists.  We can then check that zsh/foo is already loaded,
> and is already providing builtin bar.

Gah.  This turns out to be completely trivial.  We already check if the
module is loaded, so we can ensure that it does in fact provide that
feature.  We just need to check at that point if it *is* providing that
feature.  Then we can be absolutely confident that simply telling the
user everything is OK is the right thing to do: they're already getting
the feature they've just asked for.  If it's not yet providing the
feature, marking it for autoload works unless there's a clash (it's a
little pointless since we could just enable it immediately but that's a
bit more work).

diff --git a/Src/module.c b/Src/module.c
index 5cc595c..c567b3c 100644
--- a/Src/module.c
+++ b/Src/module.c
@@ -3419,12 +3419,15 @@ autofeatures(const char *cmdnam, const char *module, char **features,
     int ret = 0, subret;
     Module defm, m;
     char **modfeatures = NULL;
+    int *modenables = NULL;
     if (module) {
 	defm = (Module)find_module(module,
 				   FINDMOD_ALIASP|FINDMOD_CREATE, NULL);
 	if ((defm->node.flags & MOD_LINKED) ? defm->u.linked :
-	    defm->u.handle)
+	    defm->u.handle) {
 	    (void)features_module(defm, &modfeatures);
+	    (void)enables_module(defm, &modenables);
+	}
     } else
 	defm = NULL;
 
@@ -3544,6 +3547,16 @@ autofeatures(const char *cmdnam, const char *module, char **features,
 		    ret = 1;
 		    continue;
 		}
+		/*
+		 * If the feature is already provided by the module, there's
+		 * nothing more to do.
+		 */
+		if (modenables[ptr-modfeatures])
+		    continue;
+		/*
+		 * Otherwise, marking it for autoload will do the
+		 * right thing when the feature is eventually usd.
+		 */
 	    }
 	    if (!m->autoloads) {
 		m->autoloads = znewlinklist();

-- 
Peter Stephenson <p.w.stephenson@xxxxxxxxxxxx>
Web page now at http://homepage.ntlworld.com/p.w.stephenson/



Messages sorted by: Reverse Date, Date, Thread, Author