mirror of
https://github.com/neovim/neovim.git
synced 2026-06-11 06:18:12 +00:00
* add vim.json.encode and vim.json.decode
* use vim.NIL instead of cjson.null
* resolve strict-prototypes warnings
* The following benchmark shows an approximately 2.5x (750 ms vs 300 ms) improvement in deserialization performance over
vim.fn.json_decode on a medium package.json
```lua
local uv = vim.loop
local function readfile(path)
return
end
local json_url = "https://raw.githubusercontent.com/rust-analyzer/rust-analyzer/b24c8d5c89ee93d1172b4127564f5da3b0c88dad/editors/code/package.json"
io.popen(string.format('curl -v -f -L -O %q &> /dev/null', json_url))
local json_string = io.open('package.json'):read '*a'
uv.update_time()
local start = uv.hrtime()
for i = 1,1000 do
vim.fn.json_decode(json_string)
end
uv.update_time()
print(string.format("Deserialization time vim.fn.json_decode: %s ms", (uv.hrtime() - start) * (1e-6)))
uv.update_time()
local start = uv.hrtime()
for i = 1,1000 do
vim.json.decode(json_string)
end
uv.update_time()
print(string.format("Deserialization time vim.json.decode: %s ms", (uv.hrtime() - start) * (1e-6)))
```
Co-Authored-By: Björn Linse <bjorn.linse@gmail.com>
23 lines
522 B
C
23 lines
522 B
C
/* Lua CJSON floating point conversion routines */
|
|
|
|
/* Buffer required to store the largest string representation of a double.
|
|
*
|
|
* Longest double printed with %.14g is 21 characters long:
|
|
* -1.7976931348623e+308 */
|
|
# define FPCONV_G_FMT_BUFSIZE 32
|
|
|
|
#ifdef USE_INTERNAL_FPCONV
|
|
static inline void fpconv_init()
|
|
{
|
|
/* Do nothing - not required */
|
|
}
|
|
#else
|
|
extern void fpconv_init(void);
|
|
#endif
|
|
|
|
extern int fpconv_g_fmt(char*, double, int);
|
|
extern double fpconv_strtod(const char*, char**);
|
|
|
|
/* vi:ai et sw=4 ts=4:
|
|
*/
|