|
|
@@ -52,7 +52,7 @@ class DynamicJsonBufferBase
|
|
|
: _head(NULL), _nextBlockCapacity(initialSize) {}
|
|
|
|
|
|
~DynamicJsonBufferBase() {
|
|
|
- freeAllBlocks();
|
|
|
+ clear();
|
|
|
}
|
|
|
|
|
|
// Gets the number of bytes occupied in the buffer
|
|
|
@@ -71,7 +71,13 @@ class DynamicJsonBufferBase
|
|
|
// Resets the buffer.
|
|
|
// USE WITH CAUTION: this invalidates all previously allocated data
|
|
|
void clear() {
|
|
|
- freeAllBlocks();
|
|
|
+ Block* currentBlock = _head;
|
|
|
+ while (currentBlock != NULL) {
|
|
|
+ _nextBlockCapacity = currentBlock->capacity;
|
|
|
+ Block* nextBlock = currentBlock->next;
|
|
|
+ _allocator.deallocate(currentBlock);
|
|
|
+ currentBlock = nextBlock;
|
|
|
+ }
|
|
|
_head = 0;
|
|
|
}
|
|
|
|
|
|
@@ -144,16 +150,6 @@ class DynamicJsonBufferBase
|
|
|
return true;
|
|
|
}
|
|
|
|
|
|
- void freeAllBlocks() {
|
|
|
- Block* currentBlock = _head;
|
|
|
-
|
|
|
- while (currentBlock != NULL) {
|
|
|
- Block* nextBlock = currentBlock->next;
|
|
|
- _allocator.deallocate(currentBlock);
|
|
|
- currentBlock = nextBlock;
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
TAllocator _allocator;
|
|
|
Block* _head;
|
|
|
size_t _nextBlockCapacity;
|