Removing mallocs in main library. (#1468)
This commit is contained in:
parent
4811c8036b
commit
0c199cffc3
|
@ -30,7 +30,7 @@ private:
|
|||
|
||||
// Routines to print masks and text for debugging bitmask operations
|
||||
simdjson_unused static char * format_input_text_64(const uint8_t *text) {
|
||||
static char *buf = reinterpret_cast<char*>(malloc(sizeof(simd8x64<uint8_t>) + 1));
|
||||
static char buf[sizeof(simd8x64<uint8_t>) + 1];
|
||||
for (size_t i=0; i<sizeof(simd8x64<uint8_t>); i++) {
|
||||
buf[i] = int8_t(text[i]) < ' ' ? '_' : int8_t(text[i]);
|
||||
}
|
||||
|
@ -40,7 +40,7 @@ simdjson_unused static char * format_input_text_64(const uint8_t *text) {
|
|||
|
||||
// Routines to print masks and text for debugging bitmask operations
|
||||
simdjson_unused static char * format_input_text(const simd8x64<uint8_t>& in) {
|
||||
static char *buf = reinterpret_cast<char*>(malloc(sizeof(simd8x64<uint8_t>) + 1));
|
||||
static char buf[sizeof(simd8x64<uint8_t>) + 1];
|
||||
in.store(reinterpret_cast<uint8_t*>(buf));
|
||||
for (size_t i=0; i<sizeof(simd8x64<uint8_t>); i++) {
|
||||
if (buf[i] < ' ') { buf[i] = '_'; }
|
||||
|
@ -50,7 +50,7 @@ simdjson_unused static char * format_input_text(const simd8x64<uint8_t>& in) {
|
|||
}
|
||||
|
||||
simdjson_unused static char * format_mask(uint64_t mask) {
|
||||
static char *buf = reinterpret_cast<char*>(malloc(64 + 1));
|
||||
static char buf[sizeof(simd8x64<uint8_t>) + 1];
|
||||
for (size_t i=0; i<64; i++) {
|
||||
buf[i] = (mask & (size_t(1) << i)) ? 'X' : ' ';
|
||||
}
|
||||
|
|
|
@ -177,12 +177,11 @@ simdjson_warn_unused simdjson_really_inline error_code tape_builder::visit_root_
|
|||
// practice unless you are in the strange scenario where you have many JSON
|
||||
// documents made of single atoms.
|
||||
//
|
||||
uint8_t *copy = static_cast<uint8_t *>(malloc(iter.remaining_len() + SIMDJSON_PADDING));
|
||||
if (copy == nullptr) { return MEMALLOC; }
|
||||
std::memcpy(copy, value, iter.remaining_len());
|
||||
std::memset(copy + iter.remaining_len(), ' ', SIMDJSON_PADDING);
|
||||
error_code error = visit_number(iter, copy);
|
||||
free(copy);
|
||||
std::unique_ptr<uint8_t[]>copy(new (std::nothrow) uint8_t[iter.remaining_len() + SIMDJSON_PADDING]);
|
||||
if (copy.get() == nullptr) { return MEMALLOC; }
|
||||
std::memcpy(copy.get(), value, iter.remaining_len());
|
||||
std::memset(copy.get() + iter.remaining_len(), ' ', SIMDJSON_PADDING);
|
||||
error_code error = visit_number(iter, copy.get());
|
||||
return error;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue