forked from bblanchon/ArduinoJson
Reduced sze by 26 bytes by inlining getOrCreateNodeAt()
This commit is contained in:
@ -99,10 +99,6 @@ class JsonObject : public Internals::JsonPrintable<JsonObject>,
|
|||||||
// Returns the list node that matches the specified key.
|
// Returns the list node that matches the specified key.
|
||||||
node_type *getNodeAt(key_type key) const;
|
node_type *getNodeAt(key_type key) const;
|
||||||
|
|
||||||
// Returns the list node that matches the specified key, creating it if
|
|
||||||
// needed.
|
|
||||||
node_type *getOrCreateNodeAt(key_type key);
|
|
||||||
|
|
||||||
// The instance returned by JsonObject::invalid()
|
// The instance returned by JsonObject::invalid()
|
||||||
static JsonObject _invalid;
|
static JsonObject _invalid;
|
||||||
};
|
};
|
||||||
|
@ -29,8 +29,16 @@ const JsonVariant &JsonObject::at(const char *key) const {
|
|||||||
}
|
}
|
||||||
|
|
||||||
JsonVariant &JsonObject::operator[](const char *key) {
|
JsonVariant &JsonObject::operator[](const char *key) {
|
||||||
node_type *node = getOrCreateNodeAt(key);
|
node_type *existingNode = getNodeAt(key);
|
||||||
return node ? node->content.value : JsonVariant::invalid();
|
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)); }
|
void JsonObject::remove(char const *key) { removeNode(getNodeAt(key)); }
|
||||||
@ -56,18 +64,6 @@ JsonObject::node_type *JsonObject::getNodeAt(const char *key) const {
|
|||||||
return NULL;
|
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 {
|
void JsonObject::writeTo(JsonWriter &writer) const {
|
||||||
node_type *node = _firstNode;
|
node_type *node = _firstNode;
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user