pike.git/
src/
mapping.c
Branch:
Tag:
Non-build tags
All tags
No tags
2017-03-01
2017-03-01 19:09:14 by Martin Karlgren <marty@roxen.com>
915ea27f2c95dfe9df24970dedf1a943bab4e489 (
40
lines) (+
27
/-
13
)
[
Show
|
Annotate
]
Branch:
marty/mapping_rehash_fix
Mapping: Don't double hashsize on every insert when md has multiple refs.
540:
/* NB: Code duplication from init_mapping(). */ if (hashsize & (hashsize - 1)) hashsize = find_next_power(hashsize);
-
if ((md->hashsize == hashsize) && (md->refs == 1)) return m;
+
if ((md->hashsize == hashsize) && (md->refs == 1)
+
#ifndef PIKE_MAPPING_KEYPAIR_LOOP
+
&& md->free_list
+
#endif
+
) return m;
init_mapping(m, hashsize, md->flags); debug_malloc_touch(m);
898:
size_t h,h2; struct keypair *k, **prev; struct mapping_data *md, *omd;
+
int md_too_small;
#ifdef PIKE_DEBUG if(m->data->refs <=0)
960:
if(d_flag>1) check_mapping(m); #endif free_mapping_data(md);
-
/* We do a re-hash here instead of copying the mapping. */
-
if(
+
+
md_too_small
=
#ifndef PIKE_MAPPING_KEYPAIR_LOOP
-
(!md->free_list)
||
+
(!md->free_list)
;
#else /* PIKE_MAPPING_KEYPAIR_LOOP */
-
(md->size >= md->num_keypairs)
||
+
(md->size >= md->num_keypairs)
;
#endif /* !PIKE_MAPPING_KEYPAIR_LOOP */
-
md->refs>1)
+
+
/*
We
do
a re-hash here instead of copying the mapping. */
+
if(
md
_too_small || md
->refs>1)
{
-
+
int base_hashsize = md->hashsize ? md->hashsize : AVG_LINK_LENGTH;
+
int shift = md_too_small ? 1 : 0;
debug_malloc_touch(m);
-
rehash(m,
md->
hashsize
?(md->hashsize
<<
1
)
:AVG_LINK_LENGTH)
;
+
rehash(m,
base_
hashsize
<<
shift
);
md=m->data; } h=h2 & ( md->hashsize - 1);
1018:
size_t h, h2; struct keypair *k, **prev; struct mapping_data *md,*omd;
+
int md_too_small;
#ifdef PIKE_DEBUG if(m->data->refs <=0)
1084:
if(t != T_INT) return 0;
-
/* no need to call PREPARE
_
*
because we re-hash instead */
-
if(
+
md
_
too_small
=
#ifndef PIKE_MAPPING_KEYPAIR_LOOP
-
!(md->free_list)
||
+
!(md->free_list)
;
#else /* PIKE_MAPPING_KEYPAIR_LOOP */
-
(md->size >= md->num_keypairs)
||
+
(md->size >= md->num_keypairs)
;
#endif /* !PIKE_MAPPING_KEYPAIR_LOOP */
-
md->refs>1)
+
+
/*
no
need
to call PREPARE_* because we re-hash instead */
+
if(
md
_too_small || md
->refs>1)
{
-
+
int base_hashsize = md->hashsize ? md->hashsize : AVG_LINK_LENGTH;
+
int shift = md_too_small ? 1 : 0;
debug_malloc_touch(m);
-
rehash(m,
md->
hashsize
?(md->hashsize
<<
1
)
:AVG_LINK_LENGTH)
;
+
rehash(m,
base_
hashsize
<<
shift
);
md=m->data; } h=h2 & ( md->hashsize - 1);