zsh-workers
 help / color / mirror / code / Atom feed
From: Felipe Contreras <felipe.contreras@gmail.com>
To: zsh-workers@zsh.org
Cc: Oliver Kiddle <okiddle@yahoo.co.uk>,
	Felipe Contreras <felipe.contreras@gmail.com>
Subject: [PATCH 2/3] completion: make: add a simpler parser
Date: Fri, 29 Jul 2022 20:03:09 -0500	[thread overview]
Message-ID: <20220730010310.3383526-3-felipe.contreras@gmail.com> (raw)
In-Reply-To: <20220730010310.3383526-1-felipe.contreras@gmail.com>

The make program does all the heavy lifting, there's no need to use a
full parser.

In the git build system I get an improvement of more than 3 times (from
3.68 to 1.07 seconds).

Signed-off-by: Felipe Contreras <felipe.contreras@gmail.com>
---
 Completion/Unix/Command/_make | 20 +++++++++++++++++++-
 1 file changed, 19 insertions(+), 1 deletion(-)

diff --git a/Completion/Unix/Command/_make b/Completion/Unix/Command/_make
index 28c529a88..94747ae58 100644
--- a/Completion/Unix/Command/_make
+++ b/Completion/Unix/Command/_make
@@ -118,6 +118,24 @@ _make-parseMakefile () {
   done
 }
 
+_make-parseDataBase () {
+  local input var TAB=$'\t' IFS=
+
+  while read input
+  do
+    case "$input " in
+      ([[:alnum:]][[:alnum:]_]#[" "$TAB]#(\?|:|::|)=*)
+      var=${input%%[ $TAB]#(\?|:|::|)=*}
+      VARIABLES[$var]=1
+      ;;
+
+      ([[*?[:alnum:]$][^$TAB:=%]#:[^=]*)
+      TARGETS+=( ${input%%:*} )
+      ;;
+    esac
+  done
+}
+
 _make() {
 
   local prev="$words[CURRENT-1]" file expl tmp is_gnu incl match basedir nul=$'\0'
@@ -239,7 +257,7 @@ _make() {
       if [[ $is_gnu == gnu ]] 
       then
         if zstyle -t ":completion:${curcontext}:targets" call-command; then
-          _make-parseMakefile < <(_call_program targets "$words[1]" -nsp --no-print-directory -f "$file" .DEFAULT 2> /dev/null)
+          _make-parseDataBase < <(_call_program targets "$words[1]" -nsp --no-print-directory -f "$file" .DEFAULT 2> /dev/null)
         else
           _make-parseMakefile < $file
         fi
-- 
2.37.1.225.gfa48d685d2



  parent reply	other threads:[~2022-07-30  1:04 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-07-30  1:03 [PATCH 0/3] completion: make: various improvements Felipe Contreras
2022-07-30  1:03 ` [PATCH 1/3] completion: make: don't build everything Felipe Contreras
2022-07-30  1:03 ` Felipe Contreras [this message]
2022-07-30  1:03 ` [PATCH 3/3] completion: make: fix whitespaces Felipe Contreras
2022-08-04  8:50   ` Jun T
2022-08-04 15:57     ` Felipe Contreras
2022-08-02 10:42 ` [PATCH 0/3] completion: make: various improvements Jun T
2022-08-02 23:02   ` Felipe Contreras
2022-08-03  8:48     ` Jun T
2022-08-03 14:36       ` Felipe Contreras
2022-08-04  9:33         ` Jun T
2022-08-04 17:03           ` Felipe Contreras

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20220730010310.3383526-3-felipe.contreras@gmail.com \
    --to=felipe.contreras@gmail.com \
    --cc=okiddle@yahoo.co.uk \
    --cc=zsh-workers@zsh.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).