Skip to content

Commit b521719

Browse files
committed
Fix old-style C-Casts
1 parent ff22e75 commit b521719

21 files changed

Lines changed: 103 additions & 105 deletions

‎benchmark/linux/linux-perf-events.h‎

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,5 +88,3 @@ template <int TYPE = PERF_TYPE_HARDWARE> class LinuxEvents {
8888
}
8989
};
9090
#endif
91-
92-
#endif

‎benchmark/statisticalmodel.cpp‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,9 +51,9 @@ stat_t simdjson_computestats(const std::string_view &p) {
5151
if (!answer.valid) {
5252
return answer;
5353
}
54-
answer.backslash_count = count_backslash((const uint8_t *)p.data(), p.size());
54+
answer.backslash_count = count_backslash(reinterpret_cast<const uint8_t *>(p.data()), p.size());
5555
answer.nonasciibyte_count =
56-
count_nonasciibytes((const uint8_t *)p.data(), p.size());
56+
count_nonasciibytes(reinterpret_cast<const uint8_t *>(p.data()), p.size());
5757
answer.byte_count = p.size();
5858
answer.integer_count = 0;
5959
answer.float_count = 0;

‎include/simdjson/jsonformatutils.h‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ static inline void print_with_escapes(const unsigned char *src, std::ostream &os
8181
default:
8282
if (*src <= 0x1F) {
8383
std::ios::fmtflags f(os.flags());
84-
os << std::hex << std::setw(4) << std::setfill('0') << (int) *src;
84+
os << std::hex << std::setw(4) << std::setfill('0') << static_cast<int>(*src);
8585
os.flags(f);
8686
} else {
8787
os << *src;
@@ -92,7 +92,7 @@ static inline void print_with_escapes(const unsigned char *src, std::ostream &os
9292
}
9393

9494
static inline void print_with_escapes(const char *src, std::ostream &os) {
95-
print_with_escapes((const unsigned char *)src, os);
95+
print_with_escapes(reinterpret_cast<const unsigned char *>(src), os);
9696
}
9797

9898
#endif

‎include/simdjson/jsonminifier.h‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ size_t jsonminify(const uint8_t *buf, size_t len, uint8_t *out);
1111

1212

1313
static inline size_t jsonminify(const char *buf, size_t len, char *out) {
14-
return jsonminify((const uint8_t *)buf, len, (uint8_t *)out);
14+
return jsonminify(reinterpret_cast<const uint8_t *>(buf), len, reinterpret_cast<uint8_t *>(out));
1515
}
1616

1717

‎include/simdjson/jsonparser.h‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ bool json_parse(const uint8_t *buf, size_t len, ParsedJson &pj, bool reallocifne
3131
// all bytes at and after buf + len are ignored (can be garbage).
3232
WARN_UNUSED
3333
inline bool json_parse(const char * buf, size_t len, ParsedJson &pj, bool reallocifneeded = true) {
34-
return json_parse((const uint8_t *) buf, len, pj, reallocifneeded);
34+
return json_parse(reinterpret_cast<const uint8_t *>(buf), len, pj, reallocifneeded);
3535
}
3636

3737
// Parse a document found in buf, need to preallocate ParsedJson.
@@ -66,7 +66,7 @@ WARN_UNUSED
6666
// The input buf should be readable up to buf + len + SIMDJSON_PADDING if reallocifneeded is false,
6767
// all bytes at and after buf + len are ignored (can be garbage).
6868
inline ParsedJson build_parsed_json(const char * buf, size_t len, bool reallocifneeded = true) {
69-
return build_parsed_json((const uint8_t *) buf, len, reallocifneeded);
69+
return build_parsed_json(reinterpret_cast<const uint8_t *>(buf), len, reallocifneeded);
7070
}
7171

7272
// convenience function

‎include/simdjson/numberparsing.h‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ static inline uint32_t parse_eight_digits_unrolled(const char *chars) {
141141
const __m128i mul_1_100 = _mm_setr_epi16(100, 1, 100, 1, 100, 1, 100, 1);
142142
const __m128i mul_1_10000 =
143143
_mm_setr_epi16(10000, 1, 10000, 1, 10000, 1, 10000, 1);
144-
const __m128i input = _mm_sub_epi8(_mm_loadu_si128((const __m128i *)chars), ascii0);
144+
const __m128i input = _mm_sub_epi8(_mm_loadu_si128(reinterpret_cast<const __m128i *>(chars)), ascii0);
145145
const __m128i t1 = _mm_maddubs_epi16(input, mul_1_10);
146146
const __m128i t2 = _mm_madd_epi16(t1, mul_1_100);
147147
const __m128i t3 = _mm_packus_epi32(t2, t2);
@@ -166,7 +166,7 @@ static never_inline bool
166166
parse_float(const uint8_t *const buf,
167167
ParsedJson &pj, const uint32_t offset,
168168
bool found_minus) {
169-
const char *p = (const char *)(buf + offset);
169+
const char *p = reinterpret_cast<const char *>(buf + offset);
170170
bool negative = false;
171171
if (found_minus) {
172172
++p;
@@ -280,7 +280,7 @@ static never_inline bool parse_large_integer(const uint8_t *const buf,
280280
ParsedJson &pj,
281281
const uint32_t offset,
282282
bool found_minus) {
283-
const char *p = (const char *)(buf + offset);
283+
const char *p = reinterpret_cast<const char *>(buf + offset);
284284

285285
bool negative = false;
286286
if (found_minus) {
@@ -352,7 +352,7 @@ static really_inline bool parse_number(const uint8_t *const buf,
352352
pj.write_tape_s64(0); // always write zero
353353
return true; // always succeeds
354354
#else
355-
const char *p = (const char *)(buf + offset);
355+
const char *p = reinterpret_cast<const char *>(buf + offset);
356356
bool negative = false;
357357
if (found_minus) {
358358
++p;

‎include/simdjson/parsedjson.h‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -68,12 +68,12 @@ struct ParsedJson {
6868

6969
// this should be considered a private function
7070
really_inline void write_tape(uint64_t val, uint8_t c) {
71-
tape[current_loc++] = val | (((uint64_t)c) << 56);
71+
tape[current_loc++] = val | ((static_cast<uint64_t>(c)) << 56);
7272
}
7373

7474
really_inline void write_tape_s64(int64_t i) {
7575
write_tape(0, 'l');
76-
tape[current_loc++] = *((uint64_t *)&i);
76+
tape[current_loc++] = *(reinterpret_cast<uint64_t *>(&i));
7777
}
7878

7979
really_inline void write_tape_double(double d) {
@@ -238,14 +238,14 @@ private :
238238
// dump bits low to high
239239
inline void dumpbits_always(uint64_t v, const std::string &msg) {
240240
for (uint32_t i = 0; i < 64; i++) {
241-
std::cout << (((v >> (uint64_t)i) & 0x1ULL) != 0u ? "1" : "_");
241+
std::cout << (((v >> static_cast<uint64_t>(i)) & 0x1ULL) != 0u ? "1" : "_");
242242
}
243243
std::cout << " " << msg.c_str() << "\n";
244244
}
245245

246246
inline void dumpbits32_always(uint32_t v, const std::string &msg) {
247247
for (uint32_t i = 0; i < 32; i++) {
248-
std::cout << (((v >> (uint32_t)i) & 0x1ULL) != 0u ? "1" : "_");
248+
std::cout << (((v >> i) & 0x1ULL) != 0u ? "1" : "_");
249249
}
250250
std::cout << " " << msg.c_str() << "\n";
251251
}

‎include/simdjson/portability.h‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,10 +46,10 @@ static inline int hamming(uint64_t input_num) {
4646
#include <x86intrin.h>
4747

4848
static inline bool add_overflow(uint64_t value1, uint64_t value2, uint64_t *result) {
49-
return __builtin_uaddll_overflow(value1, value2, (unsigned long long*)result);
49+
return __builtin_uaddll_overflow(value1, value2, static_cast<unsigned long long*>(result));
5050
}
5151
static inline bool mul_overflow(uint64_t value1, uint64_t value2, uint64_t *result) {
52-
return __builtin_umulll_overflow(value1, value2, (unsigned long long *)result);
52+
return __builtin_umulll_overflow(value1, value2, static_cast<unsigned long long *>(result));
5353
}
5454

5555
/* result might be undefined when input_num is zero */

‎include/simdjson/stage1_find_marks.h‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ bool find_structural_bits(const uint8_t *buf, size_t len, ParsedJson &pj);
99

1010
WARN_UNUSED
1111
static inline bool find_structural_bits(const char *buf, size_t len, ParsedJson &pj) {
12-
return find_structural_bits((const uint8_t *)buf, len, pj);
12+
return find_structural_bits(reinterpret_cast<const uint8_t *>(buf), len, pj);
1313
}
1414

1515
#endif

‎include/simdjson/stage2_build_tape.h‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ bool unified_machine(const uint8_t *buf, size_t len, ParsedJson &pj);
1212

1313
WARN_UNUSED
1414
static inline bool unified_machine(const char *buf, size_t len, ParsedJson &pj) {
15-
return unified_machine((const uint8_t *)buf,len,pj);
15+
return unified_machine(reinterpret_cast<const uint8_t *>(buf),len,pj);
1616
}
1717

1818
#endif

0 commit comments

Comments
 (0)