mirror of
				https://github.com/neovim/neovim.git
				synced 2025-10-26 12:27:24 +00:00 
			
		
		
		
	api: remove some redundant string copies
Now that incoming Pascal strings are NULL-terminated by default, we can skip some spurious copies.
This commit is contained in:
		| @@ -40,12 +40,9 @@ void vim_push_keys(String str) | |||||||
| /// @param[out] err Details of an error that may have occurred | /// @param[out] err Details of an error that may have occurred | ||||||
| void vim_command(String str, Error *err) | 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 |   // Run the command | ||||||
|   try_start(); |   try_start(); | ||||||
|   do_cmdline_cmd((char_u *)cmd_str); |   do_cmdline_cmd((char_u *) str.data); | ||||||
|   free(cmd_str); |  | ||||||
|   update_screen(VALID); |   update_screen(VALID); | ||||||
|   try_end(err); |   try_end(err); | ||||||
| } | } | ||||||
| @@ -60,11 +57,9 @@ void vim_command(String str, Error *err) | |||||||
| Object vim_eval(String str, Error *err) | Object vim_eval(String str, Error *err) | ||||||
| { | { | ||||||
|   Object rv; |   Object rv; | ||||||
|   char *expr_str = xstrndup(str.data, str.size); |  | ||||||
|   // Evaluate the expression |   // Evaluate the expression | ||||||
|   try_start(); |   try_start(); | ||||||
|   typval_T *expr_result = eval_expr((char_u *)expr_str, NULL); |   typval_T *expr_result = eval_expr((char_u *) str.data, NULL); | ||||||
|   free(expr_str); |  | ||||||
|  |  | ||||||
|   if (!try_end(err)) { |   if (!try_end(err)) { | ||||||
|     // No errors, convert the result |     // No errors, convert the result | ||||||
| @@ -89,10 +84,7 @@ Integer vim_strwidth(String str, Error *err) | |||||||
|     return 0; |     return 0; | ||||||
|   } |   } | ||||||
|  |  | ||||||
|   char *buf = xstrndup(str.data, str.size); |   return (Integer) mb_string2cells((char_u *) str.data); | ||||||
|   Integer rv = (Integer) mb_string2cells((char_u *) buf); |  | ||||||
|   free(buf); |  | ||||||
|   return rv; |  | ||||||
| } | } | ||||||
|  |  | ||||||
| /// Returns a list of paths contained in 'runtimepath' | /// Returns a list of paths contained in 'runtimepath' | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user
	 Nicolas Hillegeer
					Nicolas Hillegeer