Просмотр исходного кода

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

Benoît Blanchon 11 лет назад
Родитель
Сommit
0045bb3e35
2 измененных файлов с 11 добавлено и 6 удалено
  1. 10 5
      JsonGenerator/JsonArrayBase.cpp
  2. 1 1
      JsonGenerator/JsonHashTableBase.cpp

+ 10 - 5
JsonGenerator/JsonArrayBase.cpp

@@ -6,6 +6,7 @@
 #include "JsonArrayBase.h"
 
 using namespace ArduinoJson::Generator;
+using namespace ArduinoJson::Internals;
 
 size_t JsonArrayBase::printTo(Print& p) const
 {
@@ -13,14 +14,18 @@ size_t JsonArrayBase::printTo(Print& p) const
 
     n += p.write('[');
 
-    for (int i = 0; i < count; i++)
-    {
-        if (i > 0)
+    // 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--)
+    {       
+        n += current->printTo(p);
+        current++;
+
+        if (i > 1)
         {
             n += p.write(',');
         }
-
-        n += items[i].printTo(p);
     }
 
     n += p.write(']');

+ 1 - 1
JsonGenerator/JsonHashTableBase.cpp

@@ -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
 
-    KeyValuePair* current = items;
+    const KeyValuePair* current = items;
     for (int i = count; i > 0; i--)
     {       
         n += current->key.printTo(p);