diff options
author | zeertzjq <zeertzjq@outlook.com> | 2023-01-21 09:24:09 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-01-21 09:24:09 +0800 |
commit | e86d2734a93e159d44df8132dee6b994e5922d18 (patch) | |
tree | e8a3015ebc88d880f9e749a7e69fbcf0d8793037 /src/nvim/eval/funcs.c | |
parent | 1c16d0994d08f1a6c396bc46833d0bfdade29422 (diff) | |
download | rneovim-e86d2734a93e159d44df8132dee6b994e5922d18.tar.gz rneovim-e86d2734a93e159d44df8132dee6b994e5922d18.tar.bz2 rneovim-e86d2734a93e159d44df8132dee6b994e5922d18.zip |
refactor: use uint8_t for blobs and ga_append() (#21916)
A blob is used as a sequence of bytes and usually accessed individually,
not as as a NUL-terminuated string, so uint8_t should be better.
Not sure about ga_append(), but using uint8_t leads to fewer casts.
Diffstat (limited to 'src/nvim/eval/funcs.c')
-rw-r--r-- | src/nvim/eval/funcs.c | 8 |
1 files changed, 4 insertions, 4 deletions
diff --git a/src/nvim/eval/funcs.c b/src/nvim/eval/funcs.c index 1b34777a46..4692035dd9 100644 --- a/src/nvim/eval/funcs.c +++ b/src/nvim/eval/funcs.c @@ -375,7 +375,7 @@ static void f_add(typval_T *argvars, typval_T *rettv, EvalFuncData fptr) const varnumber_T n = tv_get_number_chk(&argvars[1], &error); if (!error) { - ga_append(&b->bv_ga, (char)n); + ga_append(&b->bv_ga, (uint8_t)n); tv_copy(&argvars[0], rettv); } } @@ -3584,9 +3584,9 @@ static void f_insert(typval_T *argvars, typval_T *rettv, EvalFuncData fptr) } ga_grow(&b->bv_ga, 1); - char_u *const p = (char_u *)b->bv_ga.ga_data; + uint8_t *const p = (uint8_t *)b->bv_ga.ga_data; memmove(p + before + 1, p + before, (size_t)(len - before)); - *(p + before) = (char_u)val; + *(p + before) = (uint8_t)val; b->bv_ga.ga_len++; tv_copy(&argvars[0], rettv); @@ -5976,7 +5976,7 @@ static void f_reverse(typval_T *argvars, typval_T *rettv, EvalFuncData fptr) const int len = tv_blob_len(b); for (int i = 0; i < len / 2; i++) { - const char_u tmp = tv_blob_get(b, i); + const uint8_t tmp = tv_blob_get(b, i); tv_blob_set(b, i, tv_blob_get(b, len - i - 1)); tv_blob_set(b, len - i - 1, tmp); } |