Removed innecesary check and objects release. (#79)

This commit is contained in:
Carmot 2019-02-27 01:08:13 +01:00 committed by Daniel Lemire
parent 9ddc8d6ba6
commit a22c20fab0
1 changed files with 23 additions and 26 deletions

View File

@ -38,12 +38,9 @@ bool ParsedJson::allocateCapacity(size_t len, size_t maxdepth) {
std::cerr << "capacities must be non-zero " << std::endl;
return false;
}
if (len > 0) {
if ((len <= bytecapacity) && (depthcapacity < maxdepth)) {
return true;
}
deallocate();
}
if ((len <= bytecapacity) && (depthcapacity < maxdepth))
return true;
deallocate();
isvalid = false;
bytecapacity = 0; // will only set it to len after allocations are a success
n_structural_indexes = 0;
@ -87,16 +84,11 @@ void ParsedJson::deallocate() {
depthcapacity = 0;
tapecapacity = 0;
stringcapacity = 0;
{delete[] ret_address;
}
{delete[] containing_scope_offset;
}
{delete[] tape;
}
{delete[] string_buf;
}
{delete[] structural_indexes;
}
delete[] ret_address;
delete[] containing_scope_offset;
delete[] tape;
delete[] string_buf;
delete[] structural_indexes;
isvalid = false;
}
@ -108,8 +100,9 @@ void ParsedJson::init() {
WARN_UNUSED
bool ParsedJson::printjson(std::ostream &os) {
if(!isvalid) { return false;
}
if(!isvalid) {
return false;
}
size_t tapeidx = 0;
uint64_t tape_val = tape[tapeidx];
uint8_t type = (tape_val >> 56);
@ -138,16 +131,16 @@ bool ParsedJson::printjson(std::ostream &os) {
if (!inobject[depth]) {
if ((inobjectidx[depth] > 0) && (type != ']')) {
os << ",";
}
}
inobjectidx[depth]++;
} else { // if (inobject) {
if ((inobjectidx[depth] > 0) && ((inobjectidx[depth] & 1) == 0) &&
(type != '}')) {
os << ",";
}
}
if (((inobjectidx[depth] & 1) == 1)) {
os << ":";
}
}
inobjectidx[depth]++;
}
switch (type) {
@ -158,14 +151,18 @@ bool ParsedJson::printjson(std::ostream &os) {
break;
case 'l': // we have a long int
if (tapeidx + 1 >= howmany) {
delete[] inobject;
delete[] inobjectidx;
return false;
}
}
os << static_cast<int64_t>(tape[++tapeidx]);
break;
case 'd': // we have a double
if (tapeidx + 1 >= howmany) {
if (tapeidx + 1 >= howmany){
delete[] inobject;
delete[] inobjectidx;
return false;
}
}
double answer;
memcpy(&answer, &tape[++tapeidx], sizeof(answer));
os << answer;
@ -249,14 +246,14 @@ bool ParsedJson::dump_raw_tape(std::ostream &os) {
case 'l': // we have a long int
if (tapeidx + 1 >= howmany) {
return false;
}
}
os << "integer " << static_cast<int64_t>(tape[++tapeidx]) << "\n";
break;
case 'd': // we have a double
os << "float ";
if (tapeidx + 1 >= howmany) {
return false;
}
}
double answer;
memcpy(&answer, &tape[++tapeidx], sizeof(answer));
os << answer << '\n';