From 3919f07890ac9f6f0f3e15e51731dd7fc8bf29e5 Mon Sep 17 00:00:00 2001 From: Benoit Blanchon Date: Sun, 9 Nov 2014 13:54:03 +0100 Subject: [PATCH] Reduced size by 22 bytes by removing writeEmptyArray() and writeEmptyObject() --- include/ArduinoJson/Internals/JsonWriter.hpp | 2 -- src/JsonArray.cpp | 23 +++++++---------- src/JsonObject.cpp | 27 ++++++++------------ 3 files changed, 20 insertions(+), 32 deletions(-) diff --git a/include/ArduinoJson/Internals/JsonWriter.hpp b/include/ArduinoJson/Internals/JsonWriter.hpp index e50ea322..47d944cd 100644 --- a/include/ArduinoJson/Internals/JsonWriter.hpp +++ b/include/ArduinoJson/Internals/JsonWriter.hpp @@ -30,11 +30,9 @@ class JsonWriter { void beginArray() { write('['); } void endArray() { write(']'); } - void writeEmptyArray() { write("[]"); } void beginObject() { write('{'); } void endObject() { write('}'); } - void writeEmptyObject() { write("{}"); } void writeColon() { write(':'); } void writeComma() { write(','); } diff --git a/src/JsonArray.cpp b/src/JsonArray.cpp index cea29ee1..f5fe5f16 100644 --- a/src/JsonArray.cpp +++ b/src/JsonArray.cpp @@ -44,22 +44,17 @@ JsonObject &JsonArray::createNestedObject() { } void JsonArray::writeTo(JsonWriter &writer) const { - node_type *child = _firstNode; + writer.beginArray(); - if (child) { - writer.beginArray(); + const node_type *child = _firstNode; + while (child) { + child->content.writeTo(writer); - for (;;) { - child->content.writeTo(writer); + child = child->next; + if (!child) break; - child = child->next; - if (!child) break; - - writer.writeComma(); - } - - writer.endArray(); - } else { - writer.writeEmptyArray(); + writer.writeComma(); } + + writer.endArray(); } diff --git a/src/JsonObject.cpp b/src/JsonObject.cpp index d90f6854..355d2a04 100644 --- a/src/JsonObject.cpp +++ b/src/JsonObject.cpp @@ -68,24 +68,19 @@ JsonObject::node_type *JsonObject::getNodeAt(const char *key) const { } void JsonObject::writeTo(JsonWriter &writer) const { - node_type *node = _firstNode; + writer.beginObject(); - if (node) { - writer.beginObject(); + const node_type *node = _firstNode; + while (node) { + writer.writeString(node->content.key); + writer.writeColon(); + node->content.value.writeTo(writer); - for (;;) { - writer.writeString(node->content.key); - writer.writeColon(); - node->content.value.writeTo(writer); + node = node->next; + if (!node) break; - node = node->next; - if (!node) break; - - writer.writeComma(); - } - - writer.endObject(); - } else { - writer.writeEmptyObject(); + writer.writeComma(); } + + writer.endObject(); }