From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 18693 invoked by alias); 13 Nov 2013 21:05:05 -0000 Mailing-List: contact zsh-workers-help@zsh.org; run by ezmlm Precedence: bulk X-No-Archive: yes List-Id: Zsh Workers List List-Post: List-Help: X-Seq: 31977 Received: (qmail 21785 invoked from network); 13 Nov 2013 21:04:49 -0000 X-Spam-Checker-Version: SpamAssassin 3.3.2 (2011-06-06) on f.primenet.com.au X-Spam-Level: X-Spam-Status: No, score=-2.6 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_LOW autolearn=ham version=3.3.2 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:date:from:to:subject:message-id:in-reply-to :references:mime-version:content-type:content-transfer-encoding; bh=rrI5mE5X0ge3Fp2oREeOor2eMls/ekgW6zNA0ZptaRc=; b=QcpKN08v+XJF4SnvLb4A2T3hIbvA13IoKLA8nwPMrSVmEMS+NeCDGY8RiFzFdYS5Gy ytuuTR+ccv3MnX7IuyPHNJWW3p7tTGIZJgGivXKAE1Uw88byTZyg6o3puLgtqsLpcv5k ihzbcyuPzVM4/lXwIYHegHEAUJq7nZyVr4gZLPShAGhDU7/OSHISzyL2h9TgSOkd+/KO ZiV5+aWoLKG+Dl34ltRqDr6D4Wdce0KE889N3DvuxNvlIlifWhmUybv67DTN2n9x/jeN r8iRQeIL93rnFpmJ+n6NrTvhLpBZLhuWGSeulynaqD4UjxgEVBIAAgkMHGJpv12GlRlX WnQQ== X-Gm-Message-State: ALoCoQkSjBJID5M/f+HJoiiqCQKANTY7oKjOWcU9g4KeQ4lquMV7cKrq5kTuUdxPlYWQmnmVeHQ9 X-Received: by 10.180.95.202 with SMTP id dm10mr21861187wib.62.1384373513007; Wed, 13 Nov 2013 12:11:53 -0800 (PST) X-ProxyUser-IP: 86.6.157.246 Date: Wed, 13 Nov 2013 20:11:49 +0000 From: Peter Stephenson To: Zsh Hackers' List Subject: PATCH: autoloading already loaded features Message-ID: <20131113201149.284354fb@pws-pc.ntlworld.com> In-Reply-To: <20131109223250.706e20fb@pws-pc.ntlworld.com> References: <20131106202321.4a48c77b@pws-pc.ntlworld.com> <20131107153315.GW3544@sym.noone.org> <20131107160551.7aa195dc@pwslap01u.europe.root.pri> <20131107191806.GA85153@redoubt.spodhuis.org> <131107173627.ZM24325@torch.brasslantern.com> <20131108071627.GA6216@redoubt.spodhuis.org> <20131108093822.1534aa88@pwslap01u.europe.root.pri> <131108063903.ZM25660@torch.brasslantern.com> <20131108161109.6e373049@pwslap01u.europe.root.pri> <131108181143.ZM26121@torch.brasslantern.com> <20131109223250.706e20fb@pws-pc.ntlworld.com> X-Mailer: Claws Mail 3.8.0 (GTK+ 2.24.7; x86_64-redhat-linux-gnu) Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit On Sat, 9 Nov 2013 22:32:50 +0000 Peter Stephenson 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 Web page now at http://homepage.ntlworld.com/p.w.stephenson/