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/data
!/bin/encodings
!/bin/jsonchecker
/build/*.exe
/build/gmake
/build/vs*/
......
......@@ -285,12 +285,7 @@ public:
explicit GenericValue(double d) : data_(), flags_(kNumberDoubleFlag) { data_.n.d = d; }
//! Constructor for constant string (i.e. do not make a copy of string)
GenericValue(const Ch* s, SizeType length) : data_(), flags_() {
RAPIDJSON_ASSERT(s != NULL);
flags_ = kConstStringFlag;
data_.s.str = s;
data_.s.length = length;
}
GenericValue(const Ch* s, SizeType length) : data_(), flags_() { SetStringRaw(s, length); }
//! 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)); }
......@@ -427,14 +422,8 @@ public:
A better approach is to use the now public FindMember().
*/
GenericValue& operator[](const Ch* name) {
MemberIterator member = FindMember(name);
if (member != MemberEnd())
return member->value;
else {
RAPIDJSON_ASSERT(false); // see above note
static GenericValue NullValue;
return NullValue;
}
GenericValue n(name, internal::StrLen(name));
return (*this)[n];
}
const GenericValue& operator[](const Ch* name) const { return const_cast<GenericValue&>(*this)[name]; }
......@@ -486,15 +475,8 @@ public:
\c std::map, this has been changed to MemberEnd() now.
*/
MemberIterator FindMember(const Ch* name) {
RAPIDJSON_ASSERT(name);
RAPIDJSON_ASSERT(IsObject());
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;
GenericValue n(name, internal::StrLen(name));
return FindMember(n);
}
ConstMemberIterator FindMember(const Ch* name) const { return const_cast<GenericValue&>(*this).FindMember(name); }
......@@ -565,13 +547,8 @@ public:
\note Removing member is implemented by moving the last member. So the ordering of members is changed.
*/
bool RemoveMember(const Ch* name) {
MemberIterator m = FindMember(name);
if (m != MemberEnd()) {
RemoveMember(m);
return true;
}
else
return false;
GenericValue n(name, internal::StrLen(name));
return RemoveMember(n);
}
bool RemoveMember(const GenericValue& name) {
......@@ -891,7 +868,7 @@ private:
}; // 12 bytes in 32-bit mode, 16 bytes in 64-bit mode
struct Array {
GenericValue<Encoding, Allocator>* elements;
GenericValue* elements;
SizeType size;
SizeType capacity;
}; // 12 bytes in 32-bit mode, 16 bytes in 64-bit mode
......@@ -1004,7 +981,7 @@ public:
template <typename InputStream>
GenericDocument& ParseStream(InputStream& is) {
return ParseStream<0, Encoding, InputStream>(is);
return ParseStream<kParseDefaultFlags, Encoding, InputStream>(is);
}
//! Parse JSON text from a mutable string.
......@@ -1024,7 +1001,7 @@ public:
}
GenericDocument& ParseInsitu(Ch* str) {
return ParseInsitu<0, Encoding>(str);
return ParseInsitu<kParseDefaultFlags, Encoding>(str);
}
//! Parse JSON text from a read-only string.
......@@ -1044,7 +1021,7 @@ public:
}
GenericDocument& Parse(const Ch* str) {
return Parse<0>(str);
return Parse<kParseDefaultFlags>(str);
}
//! Whether a parse error was occured in the last parsing.
......
......@@ -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 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 kParseErrorNumberMissExponent: return RAPIDJSON_ERROR_STRING("Miss exponent in number.");
......
......@@ -71,7 +71,7 @@ enum ParseErrorCode {
kParseErrorStringMissQuotationMark, //!< Missing a closing quotation mark 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.
kParseErrorNumberMissExponent //!< Miss exponent in number.
};
......@@ -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, w2));
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
p += 16;
else { // some of characters may be non-whitespace
......@@ -323,7 +323,7 @@ public:
template <typename InputStream, typename Handler>
bool Parse(InputStream& is, Handler& handler) {
return Parse<0>(is, handler);
return Parse<kParseDefaultFlags>(is, handler);
}
bool HasParseError() const { return parseErrorCode_ != kParseErrorNone; }
......@@ -610,7 +610,7 @@ private:
}
}
else
RAPIDJSON_PARSE_ERROR(kParseErrorValueInvalid, is.Tell());
RAPIDJSON_PARSE_ERROR(kParseErrorValueInvalid, s.Tell());
// Parse 64bit int
uint64_t i64 = 0;
......@@ -643,7 +643,7 @@ private:
d = (double)i64;
while (s.Peek() >= '0' && s.Peek() <= '9') {
if (d >= 1E307)
RAPIDJSON_PARSE_ERROR(kParesErrorNumberTooBig, is.Tell());
RAPIDJSON_PARSE_ERROR(kParseErrorNumberTooBig, s.Tell());
d = d * 10 + (s.Take() - '0');
}
}
......@@ -662,7 +662,7 @@ private:
--expFrac;
}
else
RAPIDJSON_PARSE_ERROR(kParseErrorNumberMissFraction, is.Tell());
RAPIDJSON_PARSE_ERROR(kParseErrorNumberMissFraction, s.Tell());
while (s.Peek() >= '0' && s.Peek() <= '9') {
if (expFrac > -16) {
......@@ -695,11 +695,11 @@ private:
while (s.Peek() >= '0' && s.Peek() <= '9') {
exp = exp * 10 + (s.Take() - '0');
if (exp > 308)
RAPIDJSON_PARSE_ERROR(kParesErrorNumberTooBig, is.Tell());
RAPIDJSON_PARSE_ERROR(kParseErrorNumberTooBig, s.Tell());
}
}
else
RAPIDJSON_PARSE_ERROR(kParseErrorNumberMissExponent, is.Tell());
RAPIDJSON_PARSE_ERROR(kParseErrorNumberMissExponent, s.Tell());
if (expMinus)
exp = -exp;
......
......@@ -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;
//char* userBuffer = (char*)malloc(userBufferSize);
......@@ -108,7 +108,7 @@ TEST_F(RapidJson, SIMD_SUFFIX(DoucmentParseInsitu_MemoryPoolAllocator)) {
//free(userBuffer);
}
TEST_F(RapidJson, SIMD_SUFFIX(DoucmentParse_MemoryPoolAllocator)) {
TEST_F(RapidJson, SIMD_SUFFIX(DocumentParse_MemoryPoolAllocator)) {
//const size_t userBufferSize = 128 * 1024;
//char* userBuffer = (char*)malloc(userBufferSize);
......@@ -130,7 +130,7 @@ TEST_F(RapidJson, SIMD_SUFFIX(DoucmentParse_MemoryPoolAllocator)) {
//free(userBuffer);
}
TEST_F(RapidJson, SIMD_SUFFIX(DoucmentParse_CrtAllocator)) {
TEST_F(RapidJson, SIMD_SUFFIX(DocumentParse_CrtAllocator)) {
for (size_t i = 0; i < kTrialCount; i++) {
memcpy(temp_, json_, length_ + 1);
GenericDocument<UTF8<>, CrtAllocator> doc;
......
......@@ -171,9 +171,9 @@ TEST(Reader, ParseNumber_Error) {
for (int i = 1; i < 310; i++)
n1e309[i] = '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.
TEST_NUMBER_ERROR(kParseErrorNumberMissFraction, "1.");
......
......@@ -27,7 +27,7 @@ TEST(Value, assignment_operator) {
template <typename Value>
void TestCopyFrom() {
Value::AllocatorType a;
typename Value::AllocatorType a;
Value v1(1234);
Value v2(v1, a); // deep copy constructor
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