mirror of
				https://github.com/eledio-devices/thirdparty-ArduinoJson.git
				synced 2025-10-31 16:14:11 +01:00 
			
		
		
		
	Reduced the size of JsonValue by removing the pointer to instance methods.
This commit is contained in:
		| @@ -7,32 +7,32 @@ | |||||||
|  |  | ||||||
| using namespace ArduinoJson::Generator; | using namespace ArduinoJson::Generator; | ||||||
|  |  | ||||||
| size_t JsonValue::printBoolTo(Print& p) const | size_t JsonValue::printBoolTo(const Content& c, Print& p) | ||||||
| { | { | ||||||
|     return p.print(content.asBool ? "true" : "false"); |     return p.print(c.asBool ? "true" : "false"); | ||||||
| } | } | ||||||
|  |  | ||||||
| size_t JsonValue::printDoubleTo(Print& p) const | size_t JsonValue::printDoubleTo(const Content& c, Print& p) | ||||||
| { | { | ||||||
|     return p.print(content.asDouble.value, content.asDouble.digits); |     return p.print(c.asDouble.value, c.asDouble.digits); | ||||||
| } | } | ||||||
|  |  | ||||||
| size_t JsonValue::printLongTo(Print& p) const | size_t JsonValue::printLongTo(const Content& c, Print& p) | ||||||
| { | { | ||||||
|     return p.print(content.asLong); |     return p.print(c.asLong); | ||||||
| } | } | ||||||
|  |  | ||||||
| size_t JsonValue::printPrintableTo(Print& p) const | size_t JsonValue::printPrintableTo(const Content& c, Print& p) | ||||||
| { | { | ||||||
|     if (content.asPrintable) |     if (c.asPrintable) | ||||||
|         return ((Printable*) content.asPrintable)->printTo(p); |         return ((Printable*) c.asPrintable)->printTo(p); | ||||||
|     else |     else | ||||||
|         return p.print("null"); |         return p.print("null"); | ||||||
| } | } | ||||||
|  |  | ||||||
| size_t JsonValue::printStringTo(Print& p) const | size_t JsonValue::printStringTo(const Content& c, Print& p) | ||||||
| { | { | ||||||
|     const char* s = content.asString; |     const char* s = c.asString; | ||||||
|  |  | ||||||
|     if (!s) |     if (!s) | ||||||
|     { |     { | ||||||
|   | |||||||
| @@ -21,38 +21,38 @@ namespace ArduinoJson | |||||||
|             } |             } | ||||||
|  |  | ||||||
|             JsonValue(bool value) |             JsonValue(bool value) | ||||||
|                 : implementation(&JsonValue::printBoolTo) |                 : printToImpl(&printBoolTo) | ||||||
|             { |             { | ||||||
|                 content.asBool = value; |                 content.asBool = value; | ||||||
|             } |             } | ||||||
|  |  | ||||||
|             JsonValue(double value, uint8_t digits = 2) |             JsonValue(double value, uint8_t digits = 2) | ||||||
|                 : implementation(&JsonValue::printDoubleTo) |                 : printToImpl(&printDoubleTo) | ||||||
|             { |             { | ||||||
|                 content.asDouble.value = value; |                 content.asDouble.value = value; | ||||||
|                 content.asDouble.digits = digits; |                 content.asDouble.digits = digits; | ||||||
|             } |             } | ||||||
|  |  | ||||||
|             JsonValue(long value) |             JsonValue(long value) | ||||||
|                 : implementation(&JsonValue::printLongTo) |                 : printToImpl(&printLongTo) | ||||||
|             { |             { | ||||||
|                 content.asLong = value; |                 content.asLong = value; | ||||||
|             } |             } | ||||||
|  |  | ||||||
|             JsonValue(int value) |             JsonValue(int value) | ||||||
|                 : implementation(&JsonValue::printLongTo) |                 : printToImpl(&printLongTo) | ||||||
|             { |             { | ||||||
|                 content.asLong = value; |                 content.asLong = value; | ||||||
|             } |             } | ||||||
|  |  | ||||||
|             JsonValue(Printable& value) |             JsonValue(Printable& value) | ||||||
|                 : implementation(&JsonValue::printPrintableTo) |                 : printToImpl(&printPrintableTo) | ||||||
|             { |             { | ||||||
|                 content.asPrintable = &value; |                 content.asPrintable = &value; | ||||||
|             } |             } | ||||||
|  |  | ||||||
|             JsonValue(const char* value) |             JsonValue(const char* value) | ||||||
|                 : implementation(&JsonValue::printStringTo) |                 : printToImpl(&printStringTo) | ||||||
|             { |             { | ||||||
|                 content.asString = value; |                 content.asString = value; | ||||||
|             } |             } | ||||||
| @@ -60,7 +60,7 @@ namespace ArduinoJson | |||||||
|             size_t printTo(Print& p) const |             size_t printTo(Print& p) const | ||||||
|             { |             { | ||||||
|                 // handmade polymorphism |                 // handmade polymorphism | ||||||
|                 return (this->*implementation)(p); |                 return printToImpl(content, p); | ||||||
|             } |             } | ||||||
|  |  | ||||||
|         private: |         private: | ||||||
| @@ -79,13 +79,13 @@ namespace ArduinoJson | |||||||
|  |  | ||||||
|             Content content; |             Content content; | ||||||
|  |  | ||||||
|             size_t(JsonValue::*implementation)(Print& p)const; |             size_t(*printToImpl)(const Content&, Print& p); | ||||||
|  |  | ||||||
|             size_t printBoolTo(Print& p) const; |             static size_t printBoolTo(const Content&, Print& p); | ||||||
|             size_t printDoubleTo(Print& p) const; |             static size_t printDoubleTo(const Content&, Print& p); | ||||||
|             size_t printLongTo(Print& p) const; |             static size_t printLongTo(const Content&, Print& p); | ||||||
|             size_t printPrintableTo(Print& p) const; |             static size_t printPrintableTo(const Content&, Print& p); | ||||||
|             size_t printStringTo(Print& p) const; |             static size_t printStringTo(const Content&, Print& p); | ||||||
|         }; |         }; | ||||||
|     } |     } | ||||||
| } | } | ||||||
		Reference in New Issue
	
	Block a user