git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Alex Riesen <raa.lkml@gmail.com>
To: Junio C Hamano <gitster@pobox.com>
Cc: git@vger.kernel.org, Johannes Schindelin <Johannes.Schindelin@gmx.de>
Subject: [PATCH] Reuse cmdname->len to store pre-calculated similarity indexes
Date: Sat, 30 Aug 2008 19:13:31 +0200	[thread overview]
Message-ID: <20080830171331.GA26932@steel.home> (raw)
In-Reply-To: <81b0412b0808300944p29199600ie95c65404b6cb380@mail.gmail.com>

To avoid doing that while sorting

Signed-off-by: Alex Riesen <raa.lkml@gmail.com>
---

Alex Riesen, Sat, Aug 30, 2008 18:44:15 +0200:
> 2008/8/30 Junio C Hamano <gitster@pobox.com>:
> > I wonder if it makes sense to give an otherwise unused "score" member to
> 
> Hmm, it is a _non-existing_ member of cmdname, isn't it?
> 
> > the "struct cmdname", compute the distance only once per each command, and
> > use that as the sort key (alternatively you can have a separate int[N]
> > array to store similarity values for each item in the cmdnames list, only
> > used inside this codepath).
> 
> I think I'll take the struct cmdname->len over.

 help.c |   12 +++++++-----
 1 files changed, 7 insertions(+), 5 deletions(-)

diff --git a/help.c b/help.c
index 7bfbbcd..70d57a3 100644
--- a/help.c
+++ b/help.c
@@ -287,8 +287,8 @@ static int levenshtein_compare(const void *p1, const void *p2)
 {
 	const struct cmdname *const *c1 = p1, *const *c2 = p2;
 	const char *s1 = (*c1)->name, *s2 = (*c2)->name;
-	int l1 = similarity(s1);
-	int l2 = similarity(s2);
+	int l1 = (*c1)->len;
+	int l2 = (*c2)->len;
 	return l1 != l2 ? l1 - l2 : strcmp(s1, s2);
 }
 
@@ -312,6 +312,9 @@ const char *help_unknown_cmd(const char *cmd)
 	memcpy(main_cmds.names + main_cmds.cnt, other_cmds.names,
 		other_cmds.cnt * sizeof(other_cmds.names[0]));
 	main_cmds.cnt += other_cmds.cnt;
+	/* This reuses cmdname->len for similarity index */
+	for (i = 0; i < main_cmds.cnt; ++i)
+		main_cmds.names[i]->len = similarity(main_cmds.names[i]->name);
 
 	levenshtein_cmd = cmd;
 	qsort(main_cmds.names, main_cmds.cnt,
@@ -319,10 +322,9 @@ const char *help_unknown_cmd(const char *cmd)
 
 	if (!main_cmds.cnt)
 		die ("Uh oh.  Your system reports no Git commands at all.");
-	best_similarity = similarity(main_cmds.names[0]->name);
+	best_similarity = main_cmds.names[0]->len;
 	n = 1;
-	while (n < main_cmds.cnt &&
-		best_similarity == similarity(main_cmds.names[n]->name))
+	while (n < main_cmds.cnt && best_similarity == main_cmds.names[n]->len)
 		++n;
 	if (autocorrect && n == 1) {
 		const char *assumed;
-- 
1.6.0.1.149.g9ecb0

  reply	other threads:[~2008-08-30 17:14 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-08-28 17:15 [PATCH] Remove calculation of the longest command name from where it is not used Alex Riesen, Alex Riesen
2008-08-28 21:27 ` [PATCH updated] git wrapper: DWIM mistyped commands Alex Riesen
2008-08-28 21:28   ` [PATCH] Add help.autocorrect to enable/disable autocorrecting Alex Riesen
2008-08-29 10:11     ` Andreas Ericsson
2008-09-08  6:50     ` Junio C Hamano
2008-08-29 14:58   ` [PATCH updated] git wrapper: DWIM mistyped commands Mikael Magnusson
2008-08-30 10:12     ` Alex Riesen
2008-08-30 10:33       ` Mikael Magnusson
2008-08-31 13:50         ` [PATCH] " Alex Riesen
2008-08-31 13:54           ` [PATCH] Add help.autocorrect to enable/disable autocorrecting Alex Riesen
2008-08-31 14:49             ` Matthieu Moy
2008-08-31 16:33               ` Junio C Hamano
2008-09-01 14:42           ` [PATCH] git wrapper: DWIM mistyped commands Mikael Magnusson
2008-08-31 13:57         ` [PATCH updated] " Alex Riesen
2008-08-30 15:36   ` Junio C Hamano
2008-08-30 16:44     ` Alex Riesen
2008-08-30 17:13       ` Alex Riesen [this message]
2008-08-30 17:26         ` [PATCH] Reuse cmdname->len to store pre-calculated similarity indexes Junio C Hamano
     [not found]   ` <a2075f4c0808301510g1af01b14kd58da12dc2e80f93@mail.gmail.com>
2008-08-30 22:17     ` [PATCH updated] git wrapper: DWIM mistyped commands Felipe Carvalho Oliveira

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=20080830171331.GA26932@steel.home \
    --to=raa.lkml@gmail.com \
    --cc=Johannes.Schindelin@gmx.de \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.com \
    /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.
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).