1 #include "JSONChildren.h"
8 void jsonChildren::reserve2(jsonChildren *& mine, json_index_t amount) json_nothrow {
9 if (mine -> array != 0){
10 if (mine -> mycapacity < amount){
11 mine -> inc(amount - mine -> mycapacity);
12 #ifdef JSON_LESS_MEMORY
13 mine = jsonChildren_Reserved::newChildren_Reserved(mine, amount);
17 mine -> reserve(amount);
21 void jsonChildren::inc(
void) json_nothrow {
22 JSON_ASSERT(
this != 0, JSON_TEXT(
"Children is null inc"));
23 if (json_unlikely(mysize == mycapacity)){
24 if (json_unlikely(mycapacity == 0)){
25 JSON_ASSERT(!array, JSON_TEXT(
"Expanding a 0 capacity array, but not null"));
26 #ifdef JSON_LESS_MEMORY
27 array = json_malloc<JSONNode*>(1);
30 array = json_malloc<JSONNode*>(8);
34 #ifdef JSON_LESS_MEMORY
39 array = json_realloc<JSONNode*>(array, mycapacity);
45 void jsonChildren::inc(json_index_t amount) json_nothrow {
46 JSON_ASSERT(
this != 0, JSON_TEXT(
"Children is null inc(amount)"));
47 if (json_unlikely(amount == 0))
return;
48 if (json_likely(mysize + amount >= mycapacity)){
49 if (json_unlikely(mycapacity == 0)){
50 JSON_ASSERT(!array, JSON_TEXT(
"Expanding a 0 capacity array, but not null"));
51 #ifdef JSON_LESS_MEMORY
52 array = json_malloc<JSONNode*>(amount);
55 array = json_malloc<JSONNode*>(amount > 8 ? amount : 8);
56 mycapacity = amount > 8 ? amount : 8;
59 #ifdef JSON_LESS_MEMORY
60 mycapacity = mysize + amount;
62 while(mysize + amount > mycapacity){
66 array = json_realloc<JSONNode*>(array, mycapacity);
72 void jsonChildren::deleteAll(
void) json_nothrow {
73 JSON_ASSERT(
this != 0, JSON_TEXT(
"Children is null deleteAll"));
74 json_foreach(
this, runner){
76 JSONNode::deleteJSONNode(*runner);
80 void jsonChildren::doerase(JSONNode ** position, json_index_t number) json_nothrow {
81 JSON_ASSERT(
this != 0, JSON_TEXT(
"Children is null doerase"));
82 JSON_ASSERT(array != 0, JSON_TEXT(
"erasing something from a null array 2"));
83 JSON_ASSERT(position >= array, JSON_TEXT(
"position is beneath the start of the array 2"));
84 JSON_ASSERT(position + number <= array + mysize, JSON_TEXT(
"erasing out of bounds 2"));
85 if (position + number >= array + mysize){
86 mysize = (json_index_t)(position - array);
87 #ifndef JSON_ISO_STRICT
88 JSON_ASSERT((
long long)position - (
long long)array >= 0, JSON_TEXT(
"doing negative allocation"));
91 std::memmove(position, position + number, (mysize - (position - array) - number) *
sizeof(JSONNode *));