Apply code review suggestions

- Undo explicit bool conversion
 - Don't check for NULL before deleting pointer
This commit is contained in:
Kai Wolf 2019-02-26 09:36:28 +01:00
parent e7683820d5
commit 33341b60d8
4 changed files with 14 additions and 20 deletions

View File

@ -257,7 +257,7 @@ parse_float(const uint8_t *const buf,
} }
i *= power_of_ten[308 + exponent]; i *= power_of_ten[308 + exponent];
} }
if(is_not_structural_or_whitespace(*p) != 0u) { if(is_not_structural_or_whitespace(*p)) {
return false; return false;
} }
double d = negative ? -i : i; double d = negative ? -i : i;
@ -265,7 +265,7 @@ parse_float(const uint8_t *const buf,
#ifdef JSON_TEST_NUMBERS // for unit testing #ifdef JSON_TEST_NUMBERS // for unit testing
foundFloat(d, buf + offset); foundFloat(d, buf + offset);
#endif #endif
return is_structural_or_whitespace(*p) != 0u; return is_structural_or_whitespace(*p);
} }
// called by parse_number when we know that the output is an integer, // called by parse_number when we know that the output is an integer,
@ -336,7 +336,7 @@ static never_inline bool parse_large_integer(const uint8_t *const buf,
#ifdef JSON_TEST_NUMBERS // for unit testing #ifdef JSON_TEST_NUMBERS // for unit testing
foundInteger(signed_answer, buf + offset); foundInteger(signed_answer, buf + offset);
#endif #endif
return is_structural_or_whitespace(*p) != 0u; return is_structural_or_whitespace(*p);
} }
@ -513,7 +513,7 @@ static really_inline bool parse_number(const uint8_t *const buf,
foundInteger(i, buf + offset); foundInteger(i, buf + offset);
#endif #endif
} }
return is_structural_or_whitespace(*p) != 0u; return is_structural_or_whitespace(*p);
#endif // SIMDJSON_SKIPNUMBERPARSING #endif // SIMDJSON_SKIPNUMBERPARSING
} }

View File

@ -238,14 +238,14 @@ private :
// dump bits low to high // dump bits low to high
inline void dumpbits_always(uint64_t v, const std::string &msg) { inline void dumpbits_always(uint64_t v, const std::string &msg) {
for (uint32_t i = 0; i < 64; i++) { for (uint32_t i = 0; i < 64; i++) {
std::cout << (((v >> static_cast<uint64_t>(i)) & 0x1ULL) != 0u ? "1" : "_"); std::cout << (((v >> static_cast<uint64_t>(i)) & 0x1ULL) ? "1" : "_");
} }
std::cout << " " << msg.c_str() << "\n"; std::cout << " " << msg.c_str() << "\n";
} }
inline void dumpbits32_always(uint32_t v, const std::string &msg) { inline void dumpbits32_always(uint32_t v, const std::string &msg) {
for (uint32_t i = 0; i < 32; i++) { for (uint32_t i = 0; i < 32; i++) {
std::cout << (((v >> i) & 0x1ULL) != 0u ? "1" : "_"); std::cout << (((v >> i) & 0x1ULL) ? "1" : "_");
} }
std::cout << " " << msg.c_str() << "\n"; std::cout << " " << msg.c_str() << "\n";
} }

View File

@ -86,8 +86,7 @@ static inline void *aligned_malloc(size_t alignment, size_t size) {
#else #else
// somehow, if this is used before including "x86intrin.h", it creates an // somehow, if this is used before including "x86intrin.h", it creates an
// implicit defined warning. // implicit defined warning.
if (posix_memalign(&p, alignment, size) != 0) { return nullptr; if (posix_memalign(&p, alignment, size) != 0) { return nullptr; }
}
#endif #endif
return p; return p;
} }
@ -115,8 +114,7 @@ static inline void _mm256_storeu2_m128i(__m128i *__addr_hi, __m128i *__addr_lo,
static inline void aligned_free(void *memblock) { static inline void aligned_free(void *memblock) {
if(memblock == nullptr) { return; if(memblock == nullptr) { return; }
}
#ifdef _MSC_VER #ifdef _MSC_VER
_aligned_free(memblock); _aligned_free(memblock);
#elif defined(__MINGW32__) || defined(__MINGW64__) #elif defined(__MINGW32__) || defined(__MINGW64__)

View File

@ -62,16 +62,12 @@ bool ParsedJson::allocateCapacity(size_t len, size_t maxdepth) {
if ((string_buf == nullptr) || (tape == nullptr) || if ((string_buf == nullptr) || (tape == nullptr) ||
(containing_scope_offset == nullptr) || (ret_address == nullptr) || (structural_indexes == nullptr)) { (containing_scope_offset == nullptr) || (ret_address == nullptr) || (structural_indexes == nullptr)) {
std::cerr << "Could not allocate memory" << std::endl; std::cerr << "Could not allocate memory" << std::endl;
{delete[] ret_address; delete[] ret_address;
} delete[] containing_scope_offset;
{delete[] containing_scope_offset; delete[] tape;
} delete[] string_buf;
{delete[] tape; delete[] structural_indexes;
}
{delete[] string_buf;
}
{delete[] structural_indexes;
}
return false; return false;
} }