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.
This commit is contained in:
zeertzjq
2023-01-21 09:24:09 +08:00
committed by GitHub
parent 1c16d0994d
commit e86d2734a9
10 changed files with 32 additions and 33 deletions

View File

@@ -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);
}