Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 21 additions & 9 deletions include/rapidjson/schema.h
Original file line number Diff line number Diff line change
Expand Up @@ -357,7 +357,11 @@ class Hasher {
}

bool String(const Ch* str, SizeType len, bool) {
WriteBuffer(kStringType, str, len * sizeof(Ch));
if (len == 0) {
WriteType(kStringType);
} else {
WriteBuffer(kStringType, str, len * sizeof(Ch));
}
return true;
}

Expand Down Expand Up @@ -401,18 +405,26 @@ class Hasher {
double d;
};

bool WriteType(Type type) { return WriteBuffer(type, 0, 0); }
bool WriteType(Type type) {
uint64_t h = Hash(RAPIDJSON_UINT64_C2(0xcbf29ce4, 0x84222325), type);
*stack_.template Push<uint64_t>() = h;
return true;
}

bool WriteNumber(const Number& n) { return WriteBuffer(kNumberType, &n, sizeof(n)); }

bool WriteBuffer(Type type, const void* data, size_t len) {
// FNV-1a from http://isthe.com/chongo/tech/comp/fnv/
uint64_t h = Hash(RAPIDJSON_UINT64_C2(0xcbf29ce4, 0x84222325), type);
const unsigned char* d = static_cast<const unsigned char*>(data);
for (size_t i = 0; i < len; i++)
h = Hash(h, d[i]);
*stack_.template Push<uint64_t>() = h;
return true;
if (data != NULL && len != 0) {
uint64_t h = Hash(RAPIDJSON_UINT64_C2(0xcbf29ce4, 0x84222325), type);
const unsigned char* d = static_cast<const unsigned char*>(data);
for (size_t i = 0; i < len; i++)
h = Hash(h, d[i]);
*stack_.template Push<uint64_t>() = h;
return true;
} else {
return false;
}
}

static uint64_t Hash(uint64_t h, uint64_t d) {
Expand Down