diff options
author | Nicolas Hillegeer <nicolas@hillegeer.com> | 2014-05-30 16:58:30 +0200 |
---|---|---|
committer | Nicolas Hillegeer <nicolas@hillegeer.com> | 2014-06-08 19:21:30 +0200 |
commit | e1793949abd6e5a304ee48aaecc2c33d89a2a48d (patch) | |
tree | 830c33e6c8c6edc499086308dc3146387f55208b /src/nvim/api/vim.c | |
parent | b5640b136caf6e85337fab5309446a999419f6cb (diff) | |
download | rneovim-e1793949abd6e5a304ee48aaecc2c33d89a2a48d.tar.gz rneovim-e1793949abd6e5a304ee48aaecc2c33d89a2a48d.tar.bz2 rneovim-e1793949abd6e5a304ee48aaecc2c33d89a2a48d.zip |
api: remove some redundant string copies
Now that incoming Pascal strings are NULL-terminated by default, we can skip
some spurious copies.
Diffstat (limited to 'src/nvim/api/vim.c')
-rw-r--r-- | src/nvim/api/vim.c | 14 |
1 files changed, 3 insertions, 11 deletions
diff --git a/src/nvim/api/vim.c b/src/nvim/api/vim.c index f07bfb196e..653e6b34c7 100644 --- a/src/nvim/api/vim.c +++ b/src/nvim/api/vim.c @@ -40,12 +40,9 @@ void vim_push_keys(String str) /// @param[out] err Details of an error that may have occurred void vim_command(String str, Error *err) { - // We still use 0-terminated strings, so we must convert. - char *cmd_str = xstrndup(str.data, str.size); // Run the command try_start(); - do_cmdline_cmd((char_u *)cmd_str); - free(cmd_str); + do_cmdline_cmd((char_u *) str.data); update_screen(VALID); try_end(err); } @@ -60,11 +57,9 @@ void vim_command(String str, Error *err) Object vim_eval(String str, Error *err) { Object rv; - char *expr_str = xstrndup(str.data, str.size); // Evaluate the expression try_start(); - typval_T *expr_result = eval_expr((char_u *)expr_str, NULL); - free(expr_str); + typval_T *expr_result = eval_expr((char_u *) str.data, NULL); if (!try_end(err)) { // No errors, convert the result @@ -89,10 +84,7 @@ Integer vim_strwidth(String str, Error *err) return 0; } - char *buf = xstrndup(str.data, str.size); - Integer rv = (Integer) mb_string2cells((char_u *) buf); - free(buf); - return rv; + return (Integer) mb_string2cells((char_u *) str.data); } /// Returns a list of paths contained in 'runtimepath' |