Reduced the size of JsonArrayBase::printTo() by 18 bytes

This commit is contained in:
Benoît Blanchon
2014-07-09 13:40:09 +02:00
parent 4e61a839a5
commit 0045bb3e35
2 changed files with 11 additions and 6 deletions

View File

@ -6,6 +6,7 @@
#include "JsonArrayBase.h" #include "JsonArrayBase.h"
using namespace ArduinoJson::Generator; using namespace ArduinoJson::Generator;
using namespace ArduinoJson::Internals;
size_t JsonArrayBase::printTo(Print& p) const size_t JsonArrayBase::printTo(Print& p) const
{ {
@ -13,14 +14,18 @@ size_t JsonArrayBase::printTo(Print& p) const
n += p.write('['); n += p.write('[');
for (int i = 0; i < count; i++) // NB: the code has been optimized for a small size on a 8-bit AVR
const JsonValue* current = items;
for (int i = count; i > 0; i--)
{ {
if (i > 0) n += current->printTo(p);
current++;
if (i > 1)
{ {
n += p.write(','); n += p.write(',');
} }
n += items[i].printTo(p);
} }
n += p.write(']'); n += p.write(']');

View File

@ -15,7 +15,7 @@ size_t JsonHashTableBase::printTo(Print& p) const
// NB: the code has been optimized for a small size on a 8-bit AVR // NB: the code has been optimized for a small size on a 8-bit AVR
KeyValuePair* current = items; const KeyValuePair* current = items;
for (int i = count; i > 0; i--) for (int i = count; i > 0; i--)
{ {
n += current->key.printTo(p); n += current->key.printTo(p);