aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/nvim/buffer.c38
-rw-r--r--src/nvim/indent_c.c5
-rw-r--r--src/nvim/mbyte.c6
-rw-r--r--src/nvim/os/fs.c1
-rw-r--r--src/nvim/version.c2
5 files changed, 39 insertions, 13 deletions
diff --git a/src/nvim/buffer.c b/src/nvim/buffer.c
index 600cf575fc..26dbbe8bb5 100644
--- a/src/nvim/buffer.c
+++ b/src/nvim/buffer.c
@@ -282,6 +282,27 @@ bool buf_valid(buf_T *buf)
return false;
}
+// 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
+{
+ 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
+{
+ if (pmap_has(handle_T)(buf_map, buf->handle)) {
+ pmap_del(handle_T)(buf_map, buf->handle);
+ }
+}
+
/// Close the link to a buffer.
///
/// @param win If not NULL, set b_last_cursor.
@@ -585,6 +606,7 @@ static void free_buffer(buf_T *buf)
free_buffer_stuff(buf, TRUE);
unref_var_dict(buf->b_vars);
aubuflocal_remove(buf);
+ buf_hashtab_remove(buf);
dict_unref(buf->additional_data);
clear_fmark(&buf->b_last_cursor);
clear_fmark(&buf->b_last_insert);
@@ -1369,7 +1391,10 @@ buf_T * buflist_new(char_u *ffname, char_u *sfname, linenr_T lnum, int flags)
{
buf_T *buf;
- fname_expand(curbuf, &ffname, &sfname); /* will allocate ffname */
+ if (top_file_num == 1) {
+ buf_map = pmap_new(handle_T)();
+ }
+ fname_expand(curbuf, &ffname, &sfname); // will allocate ffname
/*
* If file name already exists in the list, update the entry.
@@ -1493,6 +1518,7 @@ buf_T * buflist_new(char_u *ffname, char_u *sfname, linenr_T lnum, int flags)
}
top_file_num = 1;
}
+ buf_hashtab_add(buf);
/*
* Always copy the options from the current buffer.
@@ -2002,19 +2028,15 @@ static char_u *fname_match(regmatch_T *rmp, char_u *name, bool ignore_case)
return match;
}
-/*
- * find file in buffer list by number
- */
+/// Find a file in the buffer list by buffer number.
buf_T *buflist_findnr(int nr)
{
if (nr == 0) {
nr = curwin->w_alt_fnum;
}
- FOR_ALL_BUFFERS(buf) {
- if (buf->b_fnum == nr) {
- return buf;
- }
+ 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/indent_c.c b/src/nvim/indent_c.c
index 6f03cf6037..7b758b4dac 100644
--- a/src/nvim/indent_c.c
+++ b/src/nvim/indent_c.c
@@ -173,9 +173,8 @@ static char_u *skip_string(char_u *p)
char_u *delim = p + 2;
char_u *paren = vim_strchr(delim, '(');
- if (paren != NULL)
- {
- long delim_len = paren - delim;
+ if (paren != NULL) {
+ ptrdiff_t delim_len = paren - delim;
for (p += 3; *p; ++p)
if (p[0] == ')' && STRNCMP(p + 1, delim, delim_len) == 0
diff --git a/src/nvim/mbyte.c b/src/nvim/mbyte.c
index ec4969d4f6..c855d68605 100644
--- a/src/nvim/mbyte.c
+++ b/src/nvim/mbyte.c
@@ -1484,6 +1484,9 @@ int utf8_to_utf16(const char *str, WCHAR **strw)
(WCHAR *)pos,
wchar_len);
assert(r == wchar_len);
+ if (r != wchar_len) {
+ EMSG2("MultiByteToWideChar failed: %d", r);
+ }
*strw = (WCHAR *)pos;
return 0;
@@ -1519,6 +1522,9 @@ int utf16_to_utf8(const WCHAR *strw, char **str)
NULL,
NULL);
assert(r == utf8_len);
+ if (r != utf8_len) {
+ EMSG2("WideCharToMultiByte failed: %d", r);
+ }
*str = pos;
return 0;
diff --git a/src/nvim/os/fs.c b/src/nvim/os/fs.c
index 4aa727733e..30e08ac129 100644
--- a/src/nvim/os/fs.c
+++ b/src/nvim/os/fs.c
@@ -939,7 +939,6 @@ char_u * os_resolve_shortcut(char_u *fname)
OLECHAR wsz[MAX_PATH];
char_u *rfname = NULL;
int len;
- int conversion_result;
IShellLinkW *pslw = NULL;
WIN32_FIND_DATAW ffdw;
diff --git a/src/nvim/version.c b/src/nvim/version.c
index 3bf87da376..3d81788a7e 100644
--- a/src/nvim/version.c
+++ b/src/nvim/version.c
@@ -404,7 +404,7 @@ static int included_patches[] = {
// 2039 NA
// 2038 NA
// 2037 NA
- // 2036,
+ 2036,
// 2035 NA
// 2034 NA
2033,