Reduced sze by 26 bytes by inlining getOrCreateNodeAt()

This commit is contained in:
Benoit Blanchon
2014-11-08 21:29:17 +01:00
parent 05db56760f
commit 36ee4876c6
2 changed files with 10 additions and 18 deletions

View File

@ -29,8 +29,16 @@ const JsonVariant &JsonObject::at(const char *key) const {
}
JsonVariant &JsonObject::operator[](const char *key) {
node_type *node = getOrCreateNodeAt(key);
return node ? node->content.value : JsonVariant::invalid();
node_type *existingNode = getNodeAt(key);
if (existingNode) return existingNode->content.value;
node_type *newNode = createNode();
if (!newNode) return JsonVariant::invalid();
newNode->content.key = key;
addNode(newNode);
return newNode->content.value;
}
void JsonObject::remove(char const *key) { removeNode(getNodeAt(key)); }
@ -56,18 +64,6 @@ JsonObject::node_type *JsonObject::getNodeAt(const char *key) const {
return NULL;
}
JsonObject::node_type *JsonObject::getOrCreateNodeAt(const char *key) {
node_type *existingNode = getNodeAt(key);
if (existingNode) return existingNode;
node_type *newNode = createNode();
if (!newNode) return NULL;
newNode->content.key = key;
addNode(newNode);
return newNode;
}
void JsonObject::writeTo(JsonWriter &writer) const {
node_type *node = _firstNode;