forked from aniani/vim
patch 8.1.1752: resizing hashtable is inefficient
Problem: Resizing hashtable is inefficient. Solution: Avoid resizing when the final size is predictable.
This commit is contained in:
@@ -286,7 +286,6 @@ hash_lock(hashtab_T *ht)
|
|||||||
++ht->ht_locked;
|
++ht->ht_locked;
|
||||||
}
|
}
|
||||||
|
|
||||||
#if 0 /* currently not used */
|
|
||||||
/*
|
/*
|
||||||
* Lock a hashtable at the specified number of entries.
|
* Lock a hashtable at the specified number of entries.
|
||||||
* Caller must make sure no more than "size" entries will be added.
|
* Caller must make sure no more than "size" entries will be added.
|
||||||
@@ -298,7 +297,6 @@ hash_lock_size(hashtab_T *ht, int size)
|
|||||||
(void)hash_may_resize(ht, size);
|
(void)hash_may_resize(ht, size);
|
||||||
++ht->ht_locked;
|
++ht->ht_locked;
|
||||||
}
|
}
|
||||||
#endif
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Unlock a hashtable: allow ht_array changes again.
|
* Unlock a hashtable: allow ht_array changes again.
|
||||||
@@ -368,10 +366,10 @@ hash_may_resize(
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
/* Use specified size. */
|
// Use specified size.
|
||||||
if ((long_u)minitems < ht->ht_used) /* just in case... */
|
if ((long_u)minitems < ht->ht_used) // just in case...
|
||||||
minitems = (int)ht->ht_used;
|
minitems = (int)ht->ht_used;
|
||||||
minsize = minitems * 3 / 2; /* array is up to 2/3 full */
|
minsize = (minitems * 3 + 1) / 2; // array is up to 2/3 full
|
||||||
}
|
}
|
||||||
|
|
||||||
newsize = HT_INIT_SIZE;
|
newsize = HT_INIT_SIZE;
|
||||||
|
|||||||
@@ -2032,7 +2032,9 @@ f_popup_getpos(typval_T *argvars, typval_T *rettv)
|
|||||||
top_extra = popup_top_extra(wp);
|
top_extra = popup_top_extra(wp);
|
||||||
left_extra = wp->w_popup_border[3] + wp->w_popup_padding[3];
|
left_extra = wp->w_popup_border[3] + wp->w_popup_padding[3];
|
||||||
|
|
||||||
|
// we know how much space we need, avoid resizing halfway
|
||||||
dict = rettv->vval.v_dict;
|
dict = rettv->vval.v_dict;
|
||||||
|
hash_lock_size(&dict->dv_hashtab, 11);
|
||||||
|
|
||||||
dict_add_number(dict, "line", wp->w_winrow + 1);
|
dict_add_number(dict, "line", wp->w_winrow + 1);
|
||||||
dict_add_number(dict, "col", wp->w_wincol + 1);
|
dict_add_number(dict, "col", wp->w_wincol + 1);
|
||||||
@@ -2050,6 +2052,8 @@ f_popup_getpos(typval_T *argvars, typval_T *rettv)
|
|||||||
dict_add_number(dict, "firstline", wp->w_topline);
|
dict_add_number(dict, "firstline", wp->w_topline);
|
||||||
dict_add_number(dict, "visible",
|
dict_add_number(dict, "visible",
|
||||||
win_valid(wp) && (wp->w_popup_flags & POPF_HIDDEN) == 0);
|
win_valid(wp) && (wp->w_popup_flags & POPF_HIDDEN) == 0);
|
||||||
|
|
||||||
|
hash_unlock(&dict->dv_hashtab);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
/*
|
/*
|
||||||
|
|||||||
@@ -9,6 +9,7 @@ int hash_add(hashtab_T *ht, char_u *key);
|
|||||||
int hash_add_item(hashtab_T *ht, hashitem_T *hi, char_u *key, hash_T hash);
|
int hash_add_item(hashtab_T *ht, hashitem_T *hi, char_u *key, hash_T hash);
|
||||||
void hash_remove(hashtab_T *ht, hashitem_T *hi);
|
void hash_remove(hashtab_T *ht, hashitem_T *hi);
|
||||||
void hash_lock(hashtab_T *ht);
|
void hash_lock(hashtab_T *ht);
|
||||||
|
void hash_lock_size(hashtab_T *ht, int size);
|
||||||
void hash_unlock(hashtab_T *ht);
|
void hash_unlock(hashtab_T *ht);
|
||||||
hash_T hash_hash(char_u *key);
|
hash_T hash_hash(char_u *key);
|
||||||
/* vim: set ft=c : */
|
/* vim: set ft=c : */
|
||||||
|
|||||||
@@ -777,6 +777,8 @@ static char *(features[]) =
|
|||||||
|
|
||||||
static int included_patches[] =
|
static int included_patches[] =
|
||||||
{ /* Add new patch number below this line */
|
{ /* Add new patch number below this line */
|
||||||
|
/**/
|
||||||
|
1752,
|
||||||
/**/
|
/**/
|
||||||
1751,
|
1751,
|
||||||
/**/
|
/**/
|
||||||
|
|||||||
Reference in New Issue
Block a user