Removed useless null checks

This commit is contained in:
Benoit Blanchon
2020-02-19 17:22:23 +01:00
parent 5a837a591e
commit ad78001241
3 changed files with 7 additions and 13 deletions

View File

@ -19,10 +19,6 @@ void check(const char* input, std::string expected) {
} }
TEST_CASE("TextFormatter::writeString()") { TEST_CASE("TextFormatter::writeString()") {
SECTION("Null") {
check(0, "null");
}
SECTION("EmptyString") { SECTION("EmptyString") {
check("", "\"\""); check("", "\"\"");
} }

View File

@ -10,6 +10,7 @@
#include <ArduinoJson/Json/EscapeSequence.hpp> #include <ArduinoJson/Json/EscapeSequence.hpp>
#include <ArduinoJson/Numbers/FloatParts.hpp> #include <ArduinoJson/Numbers/FloatParts.hpp>
#include <ArduinoJson/Numbers/Integer.hpp> #include <ArduinoJson/Numbers/Integer.hpp>
#include <ArduinoJson/Polyfills/assert.hpp>
#include <ArduinoJson/Polyfills/attributes.hpp> #include <ArduinoJson/Polyfills/attributes.hpp>
namespace ARDUINOJSON_NAMESPACE { namespace ARDUINOJSON_NAMESPACE {
@ -32,13 +33,10 @@ class TextFormatter {
} }
void writeString(const char *value) { void writeString(const char *value) {
if (!value) { ARDUINOJSON_ASSERT(value != NULL);
writeRaw("null"); writeRaw('\"');
} else { while (*value) writeChar(*value++);
writeRaw('\"'); writeRaw('\"');
while (*value) writeChar(*value++);
writeRaw('\"');
}
} }
void writeChar(char c) { void writeChar(char c) {

View File

@ -5,6 +5,7 @@
#pragma once #pragma once
#include <ArduinoJson/MsgPack/endianess.hpp> #include <ArduinoJson/MsgPack/endianess.hpp>
#include <ArduinoJson/Polyfills/assert.hpp>
#include <ArduinoJson/Polyfills/type_traits.hpp> #include <ArduinoJson/Polyfills/type_traits.hpp>
#include <ArduinoJson/Serialization/measure.hpp> #include <ArduinoJson/Serialization/measure.hpp>
#include <ArduinoJson/Serialization/serialize.hpp> #include <ArduinoJson/Serialization/serialize.hpp>
@ -70,8 +71,7 @@ class MsgPackSerializer {
} }
void visitString(const char* value) { void visitString(const char* value) {
if (!value) ARDUINOJSON_ASSERT(value != NULL);
return writeByte(0xC0); // nil
size_t n = strlen(value); size_t n = strlen(value);