aboutsummaryrefslogtreecommitdiff
path: root/src/nvim/api/buffer.c
diff options
context:
space:
mode:
authorNicolas Hillegeer <nicolas@hillegeer.com>2014-05-31 13:34:41 +0200
committerNicolas Hillegeer <nicolas@hillegeer.com>2014-06-08 19:21:35 +0200
commit54ca93465c9ecb3490da12478be48718820e3542 (patch)
tree6e2a452a33275477468368f8d0f087ad57100b5c /src/nvim/api/buffer.c
parent563698b2dc3f280b6d0d1e9156d0f1d4a4f756c4 (diff)
downloadrneovim-54ca93465c9ecb3490da12478be48718820e3542.tar.gz
rneovim-54ca93465c9ecb3490da12478be48718820e3542.tar.bz2
rneovim-54ca93465c9ecb3490da12478be48718820e3542.zip
api: unify string conversions, simplify interop
- The data member of String's can now be passed directly to functions expecting C strings, as we now guarantee that they are NUL-terminated. This obviates the need to use xstrndup and free, simplifying code and enhancing performance. - Use xmemdupz instead of xstrndup for converting String's into C strings. It's faster because it doesn't calculate strlen(string.data) (which is unnecesary as that information is already provided in string.size anyway). - Use cstr_to_string to convert from C strings to String, it is both shorter and faster than the usual strlen/xstrndup combo, which calls strlen twice. cstr_to_string internally calls strlen and then xmemdupz.
Diffstat (limited to 'src/nvim/api/buffer.c')
-rw-r--r--src/nvim/api/buffer.c11
1 files changed, 4 insertions, 7 deletions
diff --git a/src/nvim/api/buffer.c b/src/nvim/api/buffer.c
index 0fe05e69b0..adcdc6da94 100644
--- a/src/nvim/api/buffer.c
+++ b/src/nvim/api/buffer.c
@@ -184,7 +184,7 @@ void buffer_set_slice(Buffer buffer,
for (size_t i = 0; i < new_len; i++) {
String l = replacement.items[i];
- lines[i] = xstrndup(l.data, l.size);
+ lines[i] = xmemdupz(l.data, l.size);
}
try_start();
@@ -392,15 +392,12 @@ void buffer_set_name(Buffer buffer, String name, Error *err)
return;
}
- aco_save_T aco;
- int ren_ret;
- char *val = xstrndup(name.data, name.size);
-
try_start();
+
// Using aucmd_*: autocommands will be executed by rename_buffer
+ aco_save_T aco;
aucmd_prepbuf(&aco, buf);
- ren_ret = rename_buffer((char_u *)val);
- free(val);
+ int ren_ret = rename_buffer((char_u *) name.data);
aucmd_restbuf(&aco);
if (try_end(err)) {