From: Johannes Schindelin <Johannes.Schindelin@gmx.de>
To: Junio C Hamano <gitster@pobox.com>
Cc: git@vger.kernel.org, Jeff Hostetler <jeffhost@microsoft.com>
Subject: Re: [PATCH 2/5] hashmap: allow memihash computation to be continued
Date: Mon, 20 Feb 2017 13:43:38 +0100 (CET) [thread overview]
Message-ID: <alpine.DEB.2.20.1702201342020.3496@virtualbox> (raw)
In-Reply-To: <xmqq7f4onjrs.fsf@gitster.mtv.corp.google.com>
Hi Junio,
On Fri, 17 Feb 2017, Junio C Hamano wrote:
> Johannes Schindelin <johannes.schindelin@gmx.de> writes:
>
> > diff --git a/hashmap.c b/hashmap.c
> > index b10b642229c..061b7d61da6 100644
> > --- a/hashmap.c
> > +++ b/hashmap.c
> > @@ -50,6 +50,20 @@ unsigned int memihash(const void *buf, size_t len)
> > return hash;
> > }
> >
> > +/* Incoporate another chunk of data into a memihash computation. */
> > +unsigned int memihash_continue(unsigned int hash,
> > + const void *buf, size_t len)
> > +{
> > + const unsigned char *p = buf;
> > + while (len--) {
> > + unsigned int c = *p++;
> > + if (c >= 'a' && c <= 'z')
> > + c -= 'a' - 'A';
> > + hash = (hash * FNV32_PRIME) ^ c;
> > + }
> > + return hash;
> > +}
>
> This makes me wonder if we want to reduce the duplication (primarily
> to avoid risking the loop body to go out of sync) by doing:
>
> unsigned int memihash(const void *buf, size_t len)
> {
> return memihash_continue(buf, len, FNV32_BASE);
> }
>
> If an extra call level really matters, its "inline" equivalent in
> the header would probably be good.
Well, the hashing is supposed to be as fast as possible, so I would like
to avoid that extra call level. However, the end result is not so pretty
because FNV32_BASE needs to be made public (OTOH it removes more lines
than it adds):
-- snipsnap --
diff --git a/hashmap.c b/hashmap.c
index 061b7d61da6..470a0832688 100644
--- a/hashmap.c
+++ b/hashmap.c
@@ -4,7 +4,6 @@
#include "cache.h"
#include "hashmap.h"
-#define FNV32_BASE ((unsigned int) 0x811c9dc5)
#define FNV32_PRIME ((unsigned int) 0x01000193)
unsigned int strhash(const char *str)
@@ -37,19 +36,6 @@ unsigned int memhash(const void *buf, size_t len)
return hash;
}
-unsigned int memihash(const void *buf, size_t len)
-{
- unsigned int hash = FNV32_BASE;
- unsigned char *ucbuf = (unsigned char *) buf;
- while (len--) {
- unsigned int c = *ucbuf++;
- if (c >= 'a' && c <= 'z')
- c -= 'a' - 'A';
- hash = (hash * FNV32_PRIME) ^ c;
- }
- return hash;
-}
-
/* Incoporate another chunk of data into a memihash computation. */
unsigned int memihash_continue(unsigned int hash,
const void *buf, size_t len)
diff --git a/hashmap.h b/hashmap.h
index 78e14dfde71..a1a8fd7dc54 100644
--- a/hashmap.h
+++ b/hashmap.h
@@ -8,12 +8,17 @@
/* FNV-1 functions */
+#define FNV32_BASE ((unsigned int) 0x811c9dc5)
+
extern unsigned int strhash(const char *buf);
extern unsigned int strihash(const char *buf);
extern unsigned int memhash(const void *buf, size_t len);
-extern unsigned int memihash(const void *buf, size_t len);
extern unsigned int memihash_continue(unsigned int hash_seed,
const void *buf, size_t len);
+static inline unsigned int memihash(const void *buf, size_t len)
+{
+ return memihash_continue(FNV32_BASE, buf, len);
+}
static inline unsigned int sha1hash(const unsigned char *sha1)
{
next prev parent reply other threads:[~2017-02-20 12:44 UTC|newest]
Thread overview: 25+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-02-14 11:31 [PATCH 0/5] A series of performance enhancements in the memihash and name-cache area Johannes Schindelin
2017-02-14 11:31 ` [PATCH 1/5] name-hash: eliminate duplicate memihash call Johannes Schindelin
2017-02-14 11:32 ` [PATCH 2/5] hashmap: allow memihash computation to be continued Johannes Schindelin
2017-02-18 5:35 ` Junio C Hamano
2017-02-20 12:43 ` Johannes Schindelin [this message]
2017-02-20 20:27 ` Junio C Hamano
2017-02-14 11:32 ` [PATCH 3/5] name-hash: precompute hash values during preload-index Johannes Schindelin
2017-02-18 5:47 ` Junio C Hamano
2017-02-19 0:19 ` Jeff Hostetler
2017-02-19 21:45 ` Junio C Hamano
2017-02-14 11:32 ` [PATCH 4/5] name-hash: specify initial size for istate.dir_hash table Johannes Schindelin
2017-02-14 11:32 ` [PATCH 5/5] name-hash: remember previous dir_entry during lazy_init_name_hash Johannes Schindelin
2017-02-14 22:03 ` [PATCH 0/5] A series of performance enhancements in the memihash and name-cache area Jeff King
2017-02-15 14:27 ` Jeff Hostetler
2017-02-15 16:44 ` Jeff King
2017-02-18 5:56 ` Junio C Hamano
2017-02-19 0:02 ` Jeff Hostetler
2017-02-18 5:58 ` Junio C Hamano
2017-02-18 6:29 ` Jeff King
2017-02-18 20:48 ` Junio C Hamano
2017-02-18 23:52 ` Jeff Hostetler
2017-02-19 21:50 ` Junio C Hamano
2017-03-02 21:11 ` Junio C Hamano
2017-03-02 21:18 ` Jeff Hostetler
2017-03-02 21:40 ` Junio C Hamano
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
List information: http://vger.kernel.org/majordomo-info.html
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=alpine.DEB.2.20.1702201342020.3496@virtualbox \
--to=johannes.schindelin@gmx.de \
--cc=git@vger.kernel.org \
--cc=gitster@pobox.com \
--cc=jeffhost@microsoft.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.
Code repositories for project(s) associated with this public inbox
https://80x24.org/mirrors/git.git
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 read-only IMAP folder(s) and NNTP newsgroup(s).