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()") {
SECTION("Null") {
check(0, "null");
}
SECTION("EmptyString") {
check("", "\"\"");
}

View File

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

View File

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