aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/nvim/buffer.c30
-rw-r--r--src/nvim/buffer_defs.h2
2 files changed, 12 insertions, 20 deletions
diff --git a/src/nvim/buffer.c b/src/nvim/buffer.c
index 967c59ff8c..ad6fdc32c0 100644
--- a/src/nvim/buffer.c
+++ b/src/nvim/buffer.c
@@ -279,23 +279,24 @@ bool buf_valid(buf_T *buf)
return false;
}
-/// A hash table used to quickly lookup a buffer by its number.
-static hashtab_T buf_hashtab;
+// Map used to quickly lookup a buffer by its number.
+static PMap(handle_T) *buf_map = NULL;
static void buf_hashtab_add(buf_T *buf)
+ FUNC_ATTR_NONNULL_ALL
{
- snprintf((char *)buf->b_key, sizeof(buf->b_key), "%x", buf->b_fnum);
- if (hash_add(&buf_hashtab, buf->b_key) == FAIL) {
+ if (pmap_has(handle_T)(buf_map, buf->handle)) {
EMSG(_("E931: Buffer cannot be registered"));
+ } else {
+ pmap_put(handle_T)(buf_map, buf->handle, buf);
}
}
static void buf_hashtab_remove(buf_T *buf)
+ FUNC_ATTR_NONNULL_ALL
{
- hashitem_T *hi = hash_find(&buf_hashtab, buf->b_key);
-
- if (!HASHITEM_EMPTY(hi)) {
- hash_remove(&buf_hashtab, hi);
+ if (pmap_has(handle_T)(buf_map, buf->handle)) {
+ pmap_del(handle_T)(buf_map, buf->handle);
}
}
@@ -1386,7 +1387,7 @@ buf_T * buflist_new(char_u *ffname, char_u *sfname, linenr_T lnum, int flags)
buf_T *buf;
if (top_file_num == 1) {
- hash_init(&buf_hashtab);
+ buf_map = pmap_new(handle_T)();
}
fname_expand(curbuf, &ffname, &sfname); // will allocate ffname
@@ -2025,19 +2026,12 @@ static char_u *fname_match(regmatch_T *rmp, char_u *name, bool ignore_case)
/// Find a file in the buffer list by buffer number.
buf_T *buflist_findnr(int nr)
{
- char_u key[sizeof(handle_T) * 2 + 1];
- hashitem_T *hi;
-
if (nr == 0) {
nr = curwin->w_alt_fnum;
}
- snprintf((char *)key, sizeof(key), "%x", nr);
- hi = hash_find(&buf_hashtab, key);
-
- if (!HASHITEM_EMPTY(hi)) {
- return (buf_T *)(hi->hi_key -
- ((unsigned)(curbuf->b_key - (char_u *)curbuf)));
+ if (pmap_has(handle_T)(buf_map, (handle_T)nr)) {
+ return pmap_get(handle_T)(buf_map, (handle_T)nr);
}
return NULL;
}
diff --git a/src/nvim/buffer_defs.h b/src/nvim/buffer_defs.h
index 353a2e0128..2b66a07f48 100644
--- a/src/nvim/buffer_defs.h
+++ b/src/nvim/buffer_defs.h
@@ -490,8 +490,6 @@ struct file_buffer {
bool file_id_valid;
FileID file_id;
- char_u b_key[sizeof(handle_T) * 2 + 1]; // key used for buf_hashtab, holds
- // b_fnum as hex string
int b_changed; // 'modified': Set to true if something in the
// file has been changed and not written out.
int b_changedtick; // incremented for each change, also for undo