mirror of
https://github.com/git-for-windows/git.git
synced 2026-04-29 04:28:53 -05:00
name-hash: precompute hash values during preload-index
Precompute the istate.name_hash and istate.dir_hash values for each cache-entry during the preload-index phase. Move the expensive memihash() calculations from lazy_init_name_hash() to the multi-threaded preload-index phase. Signed-off-by: Jeff Hostetler <jeffhost@microsoft.com>
This commit is contained in:
committed by
Johannes Schindelin
parent
d484faac20
commit
d27bd052d2
66
name-hash.c
66
name-hash.c
@@ -50,6 +50,17 @@ static struct dir_entry *hash_dir_entry(struct index_state *istate,
|
||||
*/
|
||||
struct dir_entry *dir;
|
||||
unsigned int hash;
|
||||
int use_precomputed_dir_hash = 0;
|
||||
|
||||
if (ce->precompute_hash_state & CE_PRECOMPUTE_HASH_STATE__SET) {
|
||||
if (!(ce->precompute_hash_state & CE_PRECOMPUTE_HASH_STATE__DIR))
|
||||
return NULL; /* item does not have a parent directory */
|
||||
if (namelen == ce_namelen(ce)) {
|
||||
/* dir hash only valid for outer-most call (not recursive ones) */
|
||||
use_precomputed_dir_hash = 1;
|
||||
hash = ce->precompute_hash_dir;
|
||||
}
|
||||
}
|
||||
|
||||
/* get length of parent directory */
|
||||
while (namelen > 0 && !is_dir_sep(ce->name[namelen - 1]))
|
||||
@@ -59,7 +70,8 @@ static struct dir_entry *hash_dir_entry(struct index_state *istate,
|
||||
namelen--;
|
||||
|
||||
/* lookup existing entry for that directory */
|
||||
hash = memihash(ce->name, namelen);
|
||||
if (!use_precomputed_dir_hash)
|
||||
hash = memihash(ce->name, namelen);
|
||||
dir = find_dir_entry__hash(istate, ce->name, namelen, hash);
|
||||
if (!dir) {
|
||||
/* not found, create it and add to hash table */
|
||||
@@ -99,10 +111,18 @@ static void remove_dir_entry(struct index_state *istate, struct cache_entry *ce)
|
||||
|
||||
static void hash_index_entry(struct index_state *istate, struct cache_entry *ce)
|
||||
{
|
||||
unsigned int h;
|
||||
|
||||
if (ce->ce_flags & CE_HASHED)
|
||||
return;
|
||||
ce->ce_flags |= CE_HASHED;
|
||||
hashmap_entry_init(ce, memihash(ce->name, ce_namelen(ce)));
|
||||
|
||||
if (ce->precompute_hash_state & CE_PRECOMPUTE_HASH_STATE__SET)
|
||||
h = ce->precompute_hash_name;
|
||||
else
|
||||
h = memihash(ce->name, ce_namelen(ce));
|
||||
|
||||
hashmap_entry_init(ce, h);
|
||||
hashmap_add(&istate->name_hash, ce);
|
||||
|
||||
if (ignore_case)
|
||||
@@ -244,3 +264,45 @@ void free_name_hash(struct index_state *istate)
|
||||
hashmap_free(&istate->name_hash, 0);
|
||||
hashmap_free(&istate->dir_hash, 1);
|
||||
}
|
||||
|
||||
/*
|
||||
* Precompute the hash values for this cache_entry
|
||||
* for use in the istate.name_hash and istate.dir_hash.
|
||||
*
|
||||
* If the item is in the root directory, just compute the
|
||||
* hash value (for istate.name_hash) on the full path.
|
||||
*
|
||||
* If the item is in a subdirectory, first compute the
|
||||
* hash value for the immediate parent directory (for
|
||||
* istate.dir_hash) and then the hash value for the full
|
||||
* path by continuing the computation.
|
||||
*
|
||||
* Note that these hashes will be used by
|
||||
* wt_status_collect_untracked() as it scans the worktree
|
||||
* and maps observed paths back to the index (optionally
|
||||
* ignoring case). Therefore, we probably only *NEED* to
|
||||
* precompute this for non-skip-worktree items (since
|
||||
* status should not observe skipped items), but because
|
||||
* lazy_init_name_hash() hashes everything, we force it
|
||||
* here.
|
||||
*/
|
||||
void precompute_istate_hashes(struct cache_entry *ce)
|
||||
{
|
||||
int namelen = ce_namelen(ce);
|
||||
|
||||
while (namelen > 0 && !is_dir_sep(ce->name[namelen - 1]))
|
||||
namelen--;
|
||||
|
||||
if (namelen <= 0) {
|
||||
ce->precompute_hash_name = memihash(ce->name, ce_namelen(ce));
|
||||
ce->precompute_hash_state = CE_PRECOMPUTE_HASH_STATE__SET;
|
||||
} else {
|
||||
namelen--;
|
||||
ce->precompute_hash_dir = memihash(ce->name, namelen);
|
||||
ce->precompute_hash_name = memihash_cont(
|
||||
ce->precompute_hash_dir, &ce->name[namelen],
|
||||
ce_namelen(ce) - namelen);
|
||||
ce->precompute_hash_state =
|
||||
CE_PRECOMPUTE_HASH_STATE__SET | CE_PRECOMPUTE_HASH_STATE__DIR;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user