Commit a96b6993 authored by Milo Yip's avatar Milo Yip

Merge pull request #46 from pah/cleanup/misc

Miscellaneous cleanups
parents 80a5b909 3254a784
/bin/* /bin/*
!/bin/data
!/bin/encodings
!/bin/jsonchecker
/build/*.exe /build/*.exe
/build/gmake /build/gmake
/build/vs*/ /build/vs*/
......
...@@ -285,12 +285,7 @@ public: ...@@ -285,12 +285,7 @@ public:
explicit GenericValue(double d) : data_(), flags_(kNumberDoubleFlag) { data_.n.d = d; } explicit GenericValue(double d) : data_(), flags_(kNumberDoubleFlag) { data_.n.d = d; }
//! Constructor for constant string (i.e. do not make a copy of string) //! Constructor for constant string (i.e. do not make a copy of string)
GenericValue(const Ch* s, SizeType length) : data_(), flags_() { GenericValue(const Ch* s, SizeType length) : data_(), flags_() { SetStringRaw(s, length); }
RAPIDJSON_ASSERT(s != NULL);
flags_ = kConstStringFlag;
data_.s.str = s;
data_.s.length = length;
}
//! Constructor for constant string (i.e. do not make a copy of string) //! Constructor for constant string (i.e. do not make a copy of string)
explicit GenericValue(const Ch* s) : data_(), flags_() { SetStringRaw(s, internal::StrLen(s)); } explicit GenericValue(const Ch* s) : data_(), flags_() { SetStringRaw(s, internal::StrLen(s)); }
...@@ -427,14 +422,8 @@ public: ...@@ -427,14 +422,8 @@ public:
A better approach is to use the now public FindMember(). A better approach is to use the now public FindMember().
*/ */
GenericValue& operator[](const Ch* name) { GenericValue& operator[](const Ch* name) {
MemberIterator member = FindMember(name); GenericValue n(name, internal::StrLen(name));
if (member != MemberEnd()) return (*this)[n];
return member->value;
else {
RAPIDJSON_ASSERT(false); // see above note
static GenericValue NullValue;
return NullValue;
}
} }
const GenericValue& operator[](const Ch* name) const { return const_cast<GenericValue&>(*this)[name]; } const GenericValue& operator[](const Ch* name) const { return const_cast<GenericValue&>(*this)[name]; }
...@@ -486,15 +475,8 @@ public: ...@@ -486,15 +475,8 @@ public:
\c std::map, this has been changed to MemberEnd() now. \c std::map, this has been changed to MemberEnd() now.
*/ */
MemberIterator FindMember(const Ch* name) { MemberIterator FindMember(const Ch* name) {
RAPIDJSON_ASSERT(name); GenericValue n(name, internal::StrLen(name));
RAPIDJSON_ASSERT(IsObject()); return FindMember(n);
SizeType len = internal::StrLen(name);
MemberIterator member = MemberBegin();
for (; member != MemberEnd(); ++member)
if (member->name.data_.s.length == len && memcmp(member->name.data_.s.str, name, len * sizeof(Ch)) == 0)
break;
return member;
} }
ConstMemberIterator FindMember(const Ch* name) const { return const_cast<GenericValue&>(*this).FindMember(name); } ConstMemberIterator FindMember(const Ch* name) const { return const_cast<GenericValue&>(*this).FindMember(name); }
...@@ -565,13 +547,8 @@ public: ...@@ -565,13 +547,8 @@ public:
\note Removing member is implemented by moving the last member. So the ordering of members is changed. \note Removing member is implemented by moving the last member. So the ordering of members is changed.
*/ */
bool RemoveMember(const Ch* name) { bool RemoveMember(const Ch* name) {
MemberIterator m = FindMember(name); GenericValue n(name, internal::StrLen(name));
if (m != MemberEnd()) { return RemoveMember(n);
RemoveMember(m);
return true;
}
else
return false;
} }
bool RemoveMember(const GenericValue& name) { bool RemoveMember(const GenericValue& name) {
...@@ -891,7 +868,7 @@ private: ...@@ -891,7 +868,7 @@ private:
}; // 12 bytes in 32-bit mode, 16 bytes in 64-bit mode }; // 12 bytes in 32-bit mode, 16 bytes in 64-bit mode
struct Array { struct Array {
GenericValue<Encoding, Allocator>* elements; GenericValue* elements;
SizeType size; SizeType size;
SizeType capacity; SizeType capacity;
}; // 12 bytes in 32-bit mode, 16 bytes in 64-bit mode }; // 12 bytes in 32-bit mode, 16 bytes in 64-bit mode
...@@ -1004,7 +981,7 @@ public: ...@@ -1004,7 +981,7 @@ public:
template <typename InputStream> template <typename InputStream>
GenericDocument& ParseStream(InputStream& is) { GenericDocument& ParseStream(InputStream& is) {
return ParseStream<0, Encoding, InputStream>(is); return ParseStream<kParseDefaultFlags, Encoding, InputStream>(is);
} }
//! Parse JSON text from a mutable string. //! Parse JSON text from a mutable string.
...@@ -1024,7 +1001,7 @@ public: ...@@ -1024,7 +1001,7 @@ public:
} }
GenericDocument& ParseInsitu(Ch* str) { GenericDocument& ParseInsitu(Ch* str) {
return ParseInsitu<0, Encoding>(str); return ParseInsitu<kParseDefaultFlags, Encoding>(str);
} }
//! Parse JSON text from a read-only string. //! Parse JSON text from a read-only string.
...@@ -1044,7 +1021,7 @@ public: ...@@ -1044,7 +1021,7 @@ public:
} }
GenericDocument& Parse(const Ch* str) { GenericDocument& Parse(const Ch* str) {
return Parse<0>(str); return Parse<kParseDefaultFlags>(str);
} }
//! Whether a parse error was occured in the last parsing. //! Whether a parse error was occured in the last parsing.
......
...@@ -34,7 +34,7 @@ inline const RAPIDJSON_ERROR_CHARTYPE* GetParseError_En(ParseErrorCode parseErro ...@@ -34,7 +34,7 @@ inline const RAPIDJSON_ERROR_CHARTYPE* GetParseError_En(ParseErrorCode parseErro
case kParseErrorStringMissQuotationMark: return RAPIDJSON_ERROR_STRING("Missing a closing quotation mark in string."); case kParseErrorStringMissQuotationMark: return RAPIDJSON_ERROR_STRING("Missing a closing quotation mark in string.");
case kParseErrorStringInvalidEncoding: return RAPIDJSON_ERROR_STRING("Invalid encoidng in string."); case kParseErrorStringInvalidEncoding: return RAPIDJSON_ERROR_STRING("Invalid encoidng in string.");
case kParesErrorNumberTooBig: return RAPIDJSON_ERROR_STRING("Number too big to be stored in double."); case kParseErrorNumberTooBig: return RAPIDJSON_ERROR_STRING("Number too big to be stored in double.");
case kParseErrorNumberMissFraction: return RAPIDJSON_ERROR_STRING("Miss fraction part in number."); case kParseErrorNumberMissFraction: return RAPIDJSON_ERROR_STRING("Miss fraction part in number.");
case kParseErrorNumberMissExponent: return RAPIDJSON_ERROR_STRING("Miss exponent in number."); case kParseErrorNumberMissExponent: return RAPIDJSON_ERROR_STRING("Miss exponent in number.");
......
...@@ -71,7 +71,7 @@ enum ParseErrorCode { ...@@ -71,7 +71,7 @@ enum ParseErrorCode {
kParseErrorStringMissQuotationMark, //!< Missing a closing quotation mark in string. kParseErrorStringMissQuotationMark, //!< Missing a closing quotation mark in string.
kParseErrorStringInvalidEncoding, //!< Invalid encoidng in string. kParseErrorStringInvalidEncoding, //!< Invalid encoidng in string.
kParesErrorNumberTooBig, //!< Number too big to be stored in double. kParseErrorNumberTooBig, //!< Number too big to be stored in double.
kParseErrorNumberMissFraction, //!< Miss fraction part in number. kParseErrorNumberMissFraction, //!< Miss fraction part in number.
kParseErrorNumberMissExponent //!< Miss exponent in number. kParseErrorNumberMissExponent //!< Miss exponent in number.
}; };
...@@ -224,7 +224,7 @@ inline const char *SkipWhitespace_SIMD(const char* p) { ...@@ -224,7 +224,7 @@ inline const char *SkipWhitespace_SIMD(const char* p) {
x = _mm_or_si128(x, _mm_cmpeq_epi8(s, w1)); x = _mm_or_si128(x, _mm_cmpeq_epi8(s, w1));
x = _mm_or_si128(x, _mm_cmpeq_epi8(s, w2)); x = _mm_or_si128(x, _mm_cmpeq_epi8(s, w2));
x = _mm_or_si128(x, _mm_cmpeq_epi8(s, w3)); x = _mm_or_si128(x, _mm_cmpeq_epi8(s, w3));
unsigned short r = ~_mm_movemask_epi8(x); unsigned short r = (unsigned short)~_mm_movemask_epi8(x);
if (r == 0) // all 16 characters are whitespace if (r == 0) // all 16 characters are whitespace
p += 16; p += 16;
else { // some of characters may be non-whitespace else { // some of characters may be non-whitespace
...@@ -323,7 +323,7 @@ public: ...@@ -323,7 +323,7 @@ public:
template <typename InputStream, typename Handler> template <typename InputStream, typename Handler>
bool Parse(InputStream& is, Handler& handler) { bool Parse(InputStream& is, Handler& handler) {
return Parse<0>(is, handler); return Parse<kParseDefaultFlags>(is, handler);
} }
bool HasParseError() const { return parseErrorCode_ != kParseErrorNone; } bool HasParseError() const { return parseErrorCode_ != kParseErrorNone; }
...@@ -610,7 +610,7 @@ private: ...@@ -610,7 +610,7 @@ private:
} }
} }
else else
RAPIDJSON_PARSE_ERROR(kParseErrorValueInvalid, is.Tell()); RAPIDJSON_PARSE_ERROR(kParseErrorValueInvalid, s.Tell());
// Parse 64bit int // Parse 64bit int
uint64_t i64 = 0; uint64_t i64 = 0;
...@@ -643,7 +643,7 @@ private: ...@@ -643,7 +643,7 @@ private:
d = (double)i64; d = (double)i64;
while (s.Peek() >= '0' && s.Peek() <= '9') { while (s.Peek() >= '0' && s.Peek() <= '9') {
if (d >= 1E307) if (d >= 1E307)
RAPIDJSON_PARSE_ERROR(kParesErrorNumberTooBig, is.Tell()); RAPIDJSON_PARSE_ERROR(kParseErrorNumberTooBig, s.Tell());
d = d * 10 + (s.Take() - '0'); d = d * 10 + (s.Take() - '0');
} }
} }
...@@ -662,7 +662,7 @@ private: ...@@ -662,7 +662,7 @@ private:
--expFrac; --expFrac;
} }
else else
RAPIDJSON_PARSE_ERROR(kParseErrorNumberMissFraction, is.Tell()); RAPIDJSON_PARSE_ERROR(kParseErrorNumberMissFraction, s.Tell());
while (s.Peek() >= '0' && s.Peek() <= '9') { while (s.Peek() >= '0' && s.Peek() <= '9') {
if (expFrac > -16) { if (expFrac > -16) {
...@@ -695,11 +695,11 @@ private: ...@@ -695,11 +695,11 @@ private:
while (s.Peek() >= '0' && s.Peek() <= '9') { while (s.Peek() >= '0' && s.Peek() <= '9') {
exp = exp * 10 + (s.Take() - '0'); exp = exp * 10 + (s.Take() - '0');
if (exp > 308) if (exp > 308)
RAPIDJSON_PARSE_ERROR(kParesErrorNumberTooBig, is.Tell()); RAPIDJSON_PARSE_ERROR(kParseErrorNumberTooBig, s.Tell());
} }
} }
else else
RAPIDJSON_PARSE_ERROR(kParseErrorNumberMissExponent, is.Tell()); RAPIDJSON_PARSE_ERROR(kParseErrorNumberMissExponent, s.Tell());
if (expMinus) if (expMinus)
exp = -exp; exp = -exp;
......
...@@ -85,7 +85,7 @@ TEST_F(RapidJson, SIMD_SUFFIX(ReaderParse_DummyHandler_ValidateEncoding)) { ...@@ -85,7 +85,7 @@ TEST_F(RapidJson, SIMD_SUFFIX(ReaderParse_DummyHandler_ValidateEncoding)) {
} }
} }
TEST_F(RapidJson, SIMD_SUFFIX(DoucmentParseInsitu_MemoryPoolAllocator)) { TEST_F(RapidJson, SIMD_SUFFIX(DocumentParseInsitu_MemoryPoolAllocator)) {
//const size_t userBufferSize = 128 * 1024; //const size_t userBufferSize = 128 * 1024;
//char* userBuffer = (char*)malloc(userBufferSize); //char* userBuffer = (char*)malloc(userBufferSize);
...@@ -108,7 +108,7 @@ TEST_F(RapidJson, SIMD_SUFFIX(DoucmentParseInsitu_MemoryPoolAllocator)) { ...@@ -108,7 +108,7 @@ TEST_F(RapidJson, SIMD_SUFFIX(DoucmentParseInsitu_MemoryPoolAllocator)) {
//free(userBuffer); //free(userBuffer);
} }
TEST_F(RapidJson, SIMD_SUFFIX(DoucmentParse_MemoryPoolAllocator)) { TEST_F(RapidJson, SIMD_SUFFIX(DocumentParse_MemoryPoolAllocator)) {
//const size_t userBufferSize = 128 * 1024; //const size_t userBufferSize = 128 * 1024;
//char* userBuffer = (char*)malloc(userBufferSize); //char* userBuffer = (char*)malloc(userBufferSize);
...@@ -130,7 +130,7 @@ TEST_F(RapidJson, SIMD_SUFFIX(DoucmentParse_MemoryPoolAllocator)) { ...@@ -130,7 +130,7 @@ TEST_F(RapidJson, SIMD_SUFFIX(DoucmentParse_MemoryPoolAllocator)) {
//free(userBuffer); //free(userBuffer);
} }
TEST_F(RapidJson, SIMD_SUFFIX(DoucmentParse_CrtAllocator)) { TEST_F(RapidJson, SIMD_SUFFIX(DocumentParse_CrtAllocator)) {
for (size_t i = 0; i < kTrialCount; i++) { for (size_t i = 0; i < kTrialCount; i++) {
memcpy(temp_, json_, length_ + 1); memcpy(temp_, json_, length_ + 1);
GenericDocument<UTF8<>, CrtAllocator> doc; GenericDocument<UTF8<>, CrtAllocator> doc;
......
...@@ -171,9 +171,9 @@ TEST(Reader, ParseNumber_Error) { ...@@ -171,9 +171,9 @@ TEST(Reader, ParseNumber_Error) {
for (int i = 1; i < 310; i++) for (int i = 1; i < 310; i++)
n1e309[i] = '0'; n1e309[i] = '0';
n1e309[310] = '\0'; n1e309[310] = '\0';
TEST_NUMBER_ERROR(kParesErrorNumberTooBig, n1e309); TEST_NUMBER_ERROR(kParseErrorNumberTooBig, n1e309);
} }
TEST_NUMBER_ERROR(kParesErrorNumberTooBig, "1e309"); TEST_NUMBER_ERROR(kParseErrorNumberTooBig, "1e309");
// Miss fraction part in number. // Miss fraction part in number.
TEST_NUMBER_ERROR(kParseErrorNumberMissFraction, "1."); TEST_NUMBER_ERROR(kParseErrorNumberMissFraction, "1.");
......
...@@ -27,7 +27,7 @@ TEST(Value, assignment_operator) { ...@@ -27,7 +27,7 @@ TEST(Value, assignment_operator) {
template <typename Value> template <typename Value>
void TestCopyFrom() { void TestCopyFrom() {
Value::AllocatorType a; typename Value::AllocatorType a;
Value v1(1234); Value v1(1234);
Value v2(v1, a); // deep copy constructor Value v2(v1, a); // deep copy constructor
EXPECT_TRUE(v1.GetType() == v2.GetType()); EXPECT_TRUE(v1.GetType() == v2.GetType());
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment