summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: cf55870)
raw | patch | inline | side by side (parent: cf55870)
author | Junio C Hamano <gitster@pobox.com> | |
Wed, 23 Jan 2008 07:01:13 +0000 (23:01 -0800) | ||
committer | Junio C Hamano <gitster@pobox.com> | |
Wed, 23 Jan 2008 07:01:13 +0000 (23:01 -0800) |
This delays the hashing of index names until it becomes necessary for
the first time.
Signed-off-by: Junio C Hamano <gitster@pobox.com>
the first time.
Signed-off-by: Junio C Hamano <gitster@pobox.com>
cache.h | patch | blob | history | |
read-cache.c | patch | blob | history |
index 409738ca6b4b6dcefb60937c665bf0f1456a0f5a..e4aeff07d1ac5243aff118f57d4adb806976730b 100644 (file)
--- a/cache.h
+++ b/cache.h
struct cache_tree *cache_tree;
time_t timestamp;
void *alloc;
+ unsigned name_hash_initialized : 1;
struct hash_table name_hash;
};
diff --git a/read-cache.c b/read-cache.c
index 9477c0b398125c3759ae3692de80e75ae62e11e0..e45f4b3d61c2982ca20c910a7fc11c5bd89204be 100644 (file)
--- a/read-cache.c
+++ b/read-cache.c
return hash;
}
-static void set_index_entry(struct index_state *istate, int nr, struct cache_entry *ce)
+static void hash_index_entry(struct index_state *istate, struct cache_entry *ce)
{
void **pos;
unsigned int hash = hash_name(ce->name, ce_namelen(ce));
- istate->cache[nr] = ce;
pos = insert_hash(hash, ce, &istate->name_hash);
if (pos) {
ce->next = *pos;
}
}
+static void lazy_init_name_hash(struct index_state *istate)
+{
+ int nr;
+
+ if (istate->name_hash_initialized)
+ return;
+ for (nr = 0; nr < istate->cache_nr; nr++)
+ hash_index_entry(istate, istate->cache[nr]);
+ istate->name_hash_initialized = 1;
+}
+
+static void set_index_entry(struct index_state *istate, int nr, struct cache_entry *ce)
+{
+ istate->cache[nr] = ce;
+ if (istate->name_hash_initialized)
+ hash_index_entry(istate, ce);
+}
+
/*
* We don't actually *remove* it, we can just mark it invalid so that
* we won't find it in lookups.
int index_name_exists(struct index_state *istate, const char *name, int namelen)
{
unsigned int hash = hash_name(name, namelen);
- struct cache_entry *ce = lookup_hash(hash, &istate->name_hash);
+ struct cache_entry *ce;
+
+ lazy_init_name_hash(istate);
+ ce = lookup_hash(hash, &istate->name_hash);
while (ce) {
if (!(ce->ce_flags & CE_UNHASHED)) {