refactor(clang-tidy): remove redundant casts

This commit is contained in:
dundargoc
2023-04-26 18:28:49 +02:00
committed by GitHub
parent 6674d706d9
commit a1b045f60a
5 changed files with 47 additions and 48 deletions

View File

@@ -404,7 +404,7 @@ void nvim_buf_set_lines(uint64_t channel_id, Buffer buffer, Integer start, Integ
// If the size of the range is reducing (ie, new_len < old_len) we // If the size of the range is reducing (ie, new_len < old_len) we
// need to delete some old_len. We do this at the start, by // need to delete some old_len. We do this at the start, by
// repeatedly deleting line "start". // repeatedly deleting line "start".
size_t to_delete = (new_len < old_len) ? (size_t)(old_len - new_len) : 0; size_t to_delete = (new_len < old_len) ? old_len - new_len : 0;
for (size_t i = 0; i < to_delete; i++) { for (size_t i = 0; i < to_delete; i++) {
if (ml_delete((linenr_T)start, false) == FAIL) { if (ml_delete((linenr_T)start, false) == FAIL) {
api_set_error(err, kErrorTypeException, "Failed to delete line"); api_set_error(err, kErrorTypeException, "Failed to delete line");
@@ -648,7 +648,7 @@ void nvim_buf_set_text(uint64_t channel_id, Buffer buffer, Integer start_row, In
// If the size of the range is reducing (ie, new_len < old_len) we // If the size of the range is reducing (ie, new_len < old_len) we
// need to delete some old_len. We do this at the start, by // need to delete some old_len. We do this at the start, by
// repeatedly deleting line "start". // repeatedly deleting line "start".
size_t to_delete = (new_len < old_len) ? (size_t)(old_len - new_len) : 0; size_t to_delete = (new_len < old_len) ? old_len - new_len : 0;
for (size_t i = 0; i < to_delete; i++) { for (size_t i = 0; i < to_delete; i++) {
if (ml_delete((linenr_T)start_row, false) == FAIL) { if (ml_delete((linenr_T)start_row, false) == FAIL) {
api_set_error(err, kErrorTypeException, "Failed to delete line"); api_set_error(err, kErrorTypeException, "Failed to delete line");

View File

@@ -711,8 +711,7 @@ void ins_char_bytes(char *buf, size_t charlen)
// Copy bytes after the changed character(s). // Copy bytes after the changed character(s).
char *p = newp + col; char *p = newp + col;
if (linelen > col + oldlen) { if (linelen > col + oldlen) {
memmove(p + newlen, oldp + col + oldlen, memmove(p + newlen, oldp + col + oldlen, linelen - col - oldlen);
(size_t)(linelen - col - oldlen));
} }
// Insert or overwrite the new character. // Insert or overwrite the new character.

View File

@@ -4037,7 +4037,7 @@ int do_join(size_t count, int insert_space, int save_undo, int use_formatoptions
// Don't move anything, just compute the final line length // Don't move anything, just compute the final line length
// and setup the array of space strings lengths // and setup the array of space strings lengths
for (t = 0; t < (linenr_T)count; t++) { for (t = 0; t < (linenr_T)count; t++) {
curr_start = ml_get((linenr_T)(curwin->w_cursor.lnum + t)); curr_start = ml_get(curwin->w_cursor.lnum + t);
curr = curr_start; curr = curr_start;
if (t == 0 && setmark && (cmdmod.cmod_flags & CMOD_LOCKMARKS) == 0) { if (t == 0 && setmark && (cmdmod.cmod_flags & CMOD_LOCKMARKS) == 0) {
// Set the '[ mark. // Set the '[ mark.
@@ -5555,7 +5555,7 @@ void cursor_pos_info(dict_T *dict)
// Don't shorten this message, the user asked for it. // Don't shorten this message, the user asked for it.
tv_dict_add_nr(dict, S_LEN("words"), word_count); tv_dict_add_nr(dict, S_LEN("words"), word_count);
tv_dict_add_nr(dict, S_LEN("chars"), char_count); tv_dict_add_nr(dict, S_LEN("chars"), char_count);
tv_dict_add_nr(dict, S_LEN("bytes"), (varnumber_T)(byte_count + bom_count)); tv_dict_add_nr(dict, S_LEN("bytes"), byte_count + bom_count);
STATIC_ASSERT(sizeof("visual") == sizeof("cursor"), STATIC_ASSERT(sizeof("visual") == sizeof("cursor"),
"key_len argument in tv_dict_add_nr is wrong"); "key_len argument in tv_dict_add_nr is wrong");

View File

@@ -1641,21 +1641,21 @@ static ShaDaWriteResult shada_pack_entry(msgpack_packer *const packer, ShadaEntr
break; break;
} }
case kSDItemSearchPattern: { case kSDItemSearchPattern: {
const size_t map_size = (size_t)( const size_t map_size = (
1 // Search pattern is always present 1 // Search pattern is always present
+ ONE_IF_NOT_DEFAULT(entry, search_pattern.magic) + ONE_IF_NOT_DEFAULT(entry, search_pattern.magic)
+ ONE_IF_NOT_DEFAULT(entry, search_pattern.is_last_used) + ONE_IF_NOT_DEFAULT(entry, search_pattern.is_last_used)
+ ONE_IF_NOT_DEFAULT(entry, search_pattern.smartcase) + ONE_IF_NOT_DEFAULT(entry, search_pattern.smartcase)
+ ONE_IF_NOT_DEFAULT(entry, search_pattern.has_line_offset) + ONE_IF_NOT_DEFAULT(entry, search_pattern.has_line_offset)
+ ONE_IF_NOT_DEFAULT(entry, search_pattern.place_cursor_at_end) + ONE_IF_NOT_DEFAULT(entry, search_pattern.place_cursor_at_end)
+ ONE_IF_NOT_DEFAULT(entry, + ONE_IF_NOT_DEFAULT(entry,
search_pattern.is_substitute_pattern) search_pattern.is_substitute_pattern)
+ ONE_IF_NOT_DEFAULT(entry, search_pattern.highlighted) + ONE_IF_NOT_DEFAULT(entry, search_pattern.highlighted)
+ ONE_IF_NOT_DEFAULT(entry, search_pattern.offset) + ONE_IF_NOT_DEFAULT(entry, search_pattern.offset)
+ ONE_IF_NOT_DEFAULT(entry, search_pattern.search_backward) + ONE_IF_NOT_DEFAULT(entry, search_pattern.search_backward)
// finally, additional data: // finally, additional data:
+ (size_t)( + (
entry.data.search_pattern.additional_data entry.data.search_pattern.additional_data
? entry.data.search_pattern.additional_data->dv_hashtab.ht_used ? entry.data.search_pattern.additional_data->dv_hashtab.ht_used
: 0)); : 0));
msgpack_pack_map(spacker, map_size); msgpack_pack_map(spacker, map_size);
@@ -1682,14 +1682,14 @@ static ShaDaWriteResult shada_pack_entry(msgpack_packer *const packer, ShadaEntr
case kSDItemGlobalMark: case kSDItemGlobalMark:
case kSDItemLocalMark: case kSDItemLocalMark:
case kSDItemJump: { case kSDItemJump: {
const size_t map_size = (size_t)( const size_t map_size = (
1 // File name 1 // File name
+ ONE_IF_NOT_DEFAULT(entry, filemark.mark.lnum) + ONE_IF_NOT_DEFAULT(entry, filemark.mark.lnum)
+ ONE_IF_NOT_DEFAULT(entry, filemark.mark.col) + ONE_IF_NOT_DEFAULT(entry, filemark.mark.col)
+ ONE_IF_NOT_DEFAULT(entry, filemark.name) + ONE_IF_NOT_DEFAULT(entry, filemark.name)
// Additional entries, if any: // Additional entries, if any:
+ (size_t)( + (
entry.data.filemark.additional_data == NULL entry.data.filemark.additional_data == NULL
? 0 ? 0
: entry.data.filemark.additional_data->dv_hashtab.ht_used)); : entry.data.filemark.additional_data->dv_hashtab.ht_used));
msgpack_pack_map(spacker, map_size); msgpack_pack_map(spacker, map_size);
@@ -1715,14 +1715,14 @@ static ShaDaWriteResult shada_pack_entry(msgpack_packer *const packer, ShadaEntr
break; break;
} }
case kSDItemRegister: { case kSDItemRegister: {
const size_t map_size = (size_t)(2 // Register contents and name const size_t map_size = (2 // Register contents and name
+ ONE_IF_NOT_DEFAULT(entry, reg.type) + ONE_IF_NOT_DEFAULT(entry, reg.type)
+ ONE_IF_NOT_DEFAULT(entry, reg.width) + ONE_IF_NOT_DEFAULT(entry, reg.width)
+ ONE_IF_NOT_DEFAULT(entry, reg.is_unnamed) + ONE_IF_NOT_DEFAULT(entry, reg.is_unnamed)
// Additional entries, if any: // Additional entries, if any:
+ (size_t)(entry.data.reg.additional_data == NULL + (entry.data.reg.additional_data == NULL
? 0 ? 0
: entry.data.reg.additional_data->dv_hashtab.ht_used)); : entry.data.reg.additional_data->dv_hashtab.ht_used));
msgpack_pack_map(spacker, map_size); msgpack_pack_map(spacker, map_size);
PACK_STATIC_STR(REG_KEY_CONTENTS); PACK_STATIC_STR(REG_KEY_CONTENTS);
msgpack_pack_array(spacker, entry.data.reg.contents_size); msgpack_pack_array(spacker, entry.data.reg.contents_size);
@@ -1753,16 +1753,16 @@ static ShaDaWriteResult shada_pack_entry(msgpack_packer *const packer, ShadaEntr
case kSDItemBufferList: case kSDItemBufferList:
msgpack_pack_array(spacker, entry.data.buffer_list.size); msgpack_pack_array(spacker, entry.data.buffer_list.size);
for (size_t i = 0; i < entry.data.buffer_list.size; i++) { for (size_t i = 0; i < entry.data.buffer_list.size; i++) {
const size_t map_size = (size_t)( const size_t map_size = (
1 // Buffer name 1 // Buffer name
+ (size_t)(entry.data.buffer_list.buffers[i].pos.lnum + (size_t)(entry.data.buffer_list.buffers[i].pos.lnum
!= default_pos.lnum) != default_pos.lnum)
+ (size_t)(entry.data.buffer_list.buffers[i].pos.col + (size_t)(entry.data.buffer_list.buffers[i].pos.col
!= default_pos.col) != default_pos.col)
// Additional entries, if any: // Additional entries, if any:
+ (size_t)( + (
entry.data.buffer_list.buffers[i].additional_data entry.data.buffer_list.buffers[i].additional_data
== NULL == NULL
? 0 ? 0
: (entry.data.buffer_list.buffers[i].additional_data : (entry.data.buffer_list.buffers[i].additional_data
->dv_hashtab.ht_used))); ->dv_hashtab.ht_used)));

View File

@@ -367,7 +367,7 @@ LexExprToken viml_pexpr_next_token(ParserState *const pstate, const int flags)
// uses recorded position to scale number down when processing exponent. // uses recorded position to scale number down when processing exponent.
float_T significand_part = 0; float_T significand_part = 0;
uvarnumber_T exp_part = 0; uvarnumber_T exp_part = 0;
const size_t frac_size = (size_t)(frac_end - frac_start); const size_t frac_size = frac_end - frac_start;
for (size_t i = 0; i < frac_end; i++) { for (size_t i = 0; i < frac_end; i++) {
if (i == frac_start - 1) { if (i == frac_start - 1) {
continue; continue;