summaryrefslogtreecommitdiff
path: root/attr.c
diff options
context:
space:
mode:
authorLibravatar Junio C Hamano <gitster@pobox.com>2017-09-19 10:47:54 +0900
committerLibravatar Junio C Hamano <gitster@pobox.com>2017-09-19 10:47:54 +0900
commitb86e112056a5fb9515a28527a7c1976ec972b0db (patch)
treebe2a73c659ee4a23f37e7e582724950b33e61ac5 /attr.c
parentMerge branch 'bb/doc-eol-dirty' (diff)
parenthashmap: add API to disable item counting when threaded (diff)
downloadtgif-b86e112056a5fb9515a28527a7c1976ec972b0db.tar.xz
Merge branch 'jh/hashmap-disable-counting'
Our hashmap implementation in hashmap.[ch] is not thread-safe when adding a new item needs to expand the hashtable by rehashing; add an API to disable the automatic rehashing to work it around. * jh/hashmap-disable-counting: hashmap: add API to disable item counting when threaded
Diffstat (limited to 'attr.c')
-rw-r--r--attr.c15
1 files changed, 9 insertions, 6 deletions
diff --git a/attr.c b/attr.c
index 2f49151736..dfc3a558d8 100644
--- a/attr.c
+++ b/attr.c
@@ -151,10 +151,12 @@ struct all_attrs_item {
static void all_attrs_init(struct attr_hashmap *map, struct attr_check *check)
{
int i;
+ unsigned int size;
hashmap_lock(map);
- if (map->map.size < check->all_attrs_nr)
+ size = hashmap_get_size(&map->map);
+ if (size < check->all_attrs_nr)
die("BUG: interned attributes shouldn't be deleted");
/*
@@ -163,13 +165,13 @@ static void all_attrs_init(struct attr_hashmap *map, struct attr_check *check)
* field), reallocate the provided attr_check instance's all_attrs
* field and fill each entry with its corresponding git_attr.
*/
- if (map->map.size != check->all_attrs_nr) {
+ if (size != check->all_attrs_nr) {
struct attr_hash_entry *e;
struct hashmap_iter iter;
hashmap_iter_init(&map->map, &iter);
- REALLOC_ARRAY(check->all_attrs, map->map.size);
- check->all_attrs_nr = map->map.size;
+ REALLOC_ARRAY(check->all_attrs, size);
+ check->all_attrs_nr = size;
while ((e = hashmap_iter_next(&iter))) {
const struct git_attr *a = e->value;
@@ -237,10 +239,11 @@ static const struct git_attr *git_attr_internal(const char *name, int namelen)
if (!a) {
FLEX_ALLOC_MEM(a, name, name, namelen);
- a->attr_nr = g_attr_hashmap.map.size;
+ a->attr_nr = hashmap_get_size(&g_attr_hashmap.map);
attr_hashmap_add(&g_attr_hashmap, a->name, namelen, a);
- assert(a->attr_nr == (g_attr_hashmap.map.size - 1));
+ assert(a->attr_nr ==
+ (hashmap_get_size(&g_attr_hashmap.map) - 1));
}
hashmap_unlock(&g_attr_hashmap);