From 2552c3493bb12bb54971963546f0d7bf272731b6 Mon Sep 17 00:00:00 2001 From: Jan Steemann Date: Tue, 24 Nov 2015 12:03:20 +0100 Subject: [PATCH] updated vpack library --- .../velocypack/include/velocypack/Builder.h | 12 ++++-- 3rdParty/velocypack/src/Builder.cpp | 41 +++++++++++-------- 3rdParty/velocypack/src/HexDump.cpp | 10 ++--- 3rdParty/velocypack/src/Slice.cpp | 14 ++++--- 3rdParty/velocypack/src/fpconv.cpp | 9 ++-- 5 files changed, 47 insertions(+), 39 deletions(-) diff --git a/3rdParty/velocypack/include/velocypack/Builder.h b/3rdParty/velocypack/include/velocypack/Builder.h index bf727e53f6..1bbe509da3 100644 --- a/3rdParty/velocypack/include/velocypack/Builder.h +++ b/3rdParty/velocypack/include/velocypack/Builder.h @@ -110,16 +110,20 @@ class Builder { // at position base, also determine the length len of the attribute. // This takes into account the different possibilities for the format // of attribute names: - static uint8_t const* findAttrName(uint8_t const* base, uint64_t& len); + static uint8_t const* findAttrName(uint8_t const* base, uint64_t& len, + Options const*); static void sortObjectIndexShort(uint8_t* objBase, - std::vector& offsets); + std::vector& offsets, + Options const*); static void sortObjectIndexLong(uint8_t* objBase, - std::vector& offsets); + std::vector& offsets, + Options const*); static void sortObjectIndex(uint8_t* objBase, - std::vector& offsets); + std::vector& offsets, + Options const*); public: Options const* options; diff --git a/3rdParty/velocypack/src/Builder.cpp b/3rdParty/velocypack/src/Builder.cpp index 16a4d85c87..1078f82fa8 100644 --- a/3rdParty/velocypack/src/Builder.cpp +++ b/3rdParty/velocypack/src/Builder.cpp @@ -42,8 +42,8 @@ std::string Builder::toString() const { void Builder::doActualSort(std::vector& entries) { VELOCYPACK_ASSERT(entries.size() > 1); - std::sort(entries.begin(), entries.end(), - [](SortEntry const& a, SortEntry const& b) { + std::sort(entries.begin(), entries.end(), [](SortEntry const& a, + SortEntry const& b) { // return true iff a < b: uint8_t const* pa = a.nameStart; uint64_t sizea = a.nameSize; @@ -56,7 +56,8 @@ void Builder::doActualSort(std::vector& entries) { }); }; -uint8_t const* Builder::findAttrName(uint8_t const* base, uint64_t& len) { +uint8_t const* Builder::findAttrName(uint8_t const* base, uint64_t& len, + Options const* options) { uint8_t const b = *base; if (b >= 0x40 && b <= 0xbe) { // short UTF-8 string @@ -72,11 +73,15 @@ uint8_t const* Builder::findAttrName(uint8_t const* base, uint64_t& len) { } return base + 1 + 8; // string starts here } - throw Exception(Exception::NotImplemented, "Invalid Object key type"); + + // translate attribute name + Slice s(base, options); + return findAttrName(s.makeKey().start(), len, options); } void Builder::sortObjectIndexShort(uint8_t* objBase, - std::vector& offsets) { + std::vector& offsets, + Options const* options) { auto cmp = [&](ValueLength a, ValueLength b) -> bool { uint8_t const* aa = objBase + a; uint8_t const* bb = objBase + b; @@ -88,8 +93,8 @@ void Builder::sortObjectIndexShort(uint8_t* objBase, } else { uint64_t lena; uint64_t lenb; - aa = findAttrName(aa, lena); - bb = findAttrName(bb, lenb); + aa = findAttrName(aa, lena, options); + bb = findAttrName(bb, lenb, options); uint64_t m = (std::min)(lena, lenb); int c = memcmp(aa, bb, m); return (c < 0 || (c == 0 && lena < lenb)); @@ -99,7 +104,8 @@ void Builder::sortObjectIndexShort(uint8_t* objBase, } void Builder::sortObjectIndexLong(uint8_t* objBase, - std::vector& offsets) { + std::vector& offsets, + Options const* options) { // on some platforms we can use a thread-local vector #if __llvm__ == 1 // nono thread local @@ -116,7 +122,7 @@ void Builder::sortObjectIndexLong(uint8_t* objBase, for (ValueLength i = 0; i < offsets.size(); i++) { SortEntry e; e.offset = offsets[i]; - e.nameStart = findAttrName(objBase + e.offset, e.nameSize); + e.nameStart = findAttrName(objBase + e.offset, e.nameSize, options); entries.push_back(e); } VELOCYPACK_ASSERT(entries.size() == offsets.size()); @@ -129,11 +135,12 @@ void Builder::sortObjectIndexLong(uint8_t* objBase, } void Builder::sortObjectIndex(uint8_t* objBase, - std::vector& offsets) { + std::vector& offsets, + Options const* options) { if (offsets.size() > 32) { - sortObjectIndexLong(objBase, offsets); + sortObjectIndexLong(objBase, offsets, options); } else { - sortObjectIndexShort(objBase, offsets); + sortObjectIndexShort(objBase, offsets, options); } } @@ -304,7 +311,7 @@ void Builder::close() { if (!options->sortAttributeNames) { _start[tos] = 0x0f; // unsorted } else if (index.size() >= 2 && options->sortAttributeNames) { - sortObjectIndex(_start + tos, index); + sortObjectIndex(_start + tos, index, options); } } for (size_t i = 0; i < index.size(); i++) { @@ -376,7 +383,7 @@ bool Builder::hasKey(std::string const& key) const { } for (size_t i = 0; i < index.size(); ++i) { Slice s(_start + tos + index[i], options); - if (s.isString() && s.isEqualString(key)) { + if (s.makeKey().isEqualString(key)) { return true; } } @@ -398,10 +405,7 @@ Slice Builder::getKey(std::string const& key) const { } for (size_t i = 0; i < index.size(); ++i) { Slice s(_start + tos + index[i], options); - if (!s.isString()) { - s = s.makeKey(); - } - if (s.isString() && s.isEqualString(key)) { + if (s.makeKey().isEqualString(key)) { return Slice(s.start() + s.byteSize(), options); } } @@ -742,6 +746,7 @@ void Builder::checkAttributeUniqueness(Slice const& obj) const { std::unordered_set keys; for (size_t i = 0; i < n; ++i) { + // note: keyAt() already translates integer attributes Slice key = obj.keyAt(i); if (!key.isString()) { throw Exception(Exception::BuilderUnexpectedType, diff --git a/3rdParty/velocypack/src/HexDump.cpp b/3rdParty/velocypack/src/HexDump.cpp index 511fb62ca0..2c69f18e1d 100644 --- a/3rdParty/velocypack/src/HexDump.cpp +++ b/3rdParty/velocypack/src/HexDump.cpp @@ -48,15 +48,15 @@ std::ostream& operator<<(std::ostream& stream, HexDump const* hexdump) { for (uint8_t it : hexdump->slice) { if (current != 0) { stream << hexdump->separator; + + if (hexdump->valuesPerLine > 0 && current == hexdump->valuesPerLine) { + stream << std::endl; + current = 0; + } } stream << HexDump::toHex(it); ++current; - - if (hexdump->valuesPerLine > 0 && current == hexdump->valuesPerLine) { - stream << std::endl; - current = 0; - } } return stream; diff --git a/3rdParty/velocypack/src/Slice.cpp b/3rdParty/velocypack/src/Slice.cpp index 5afe00c03b..9084931a69 100644 --- a/3rdParty/velocypack/src/Slice.cpp +++ b/3rdParty/velocypack/src/Slice.cpp @@ -214,7 +214,9 @@ unsigned int const Slice::FirstSubMap[32] = { // translates an integer key into a string Slice Slice::translate() const { - VELOCYPACK_ASSERT(isSmallInt() || isUInt()); + if (!isSmallInt() && !isUInt()) { + throw Exception(Exception::NeedAttributeTranslator); + } uint64_t id = getUInt(); if (options->attributeTranslator == nullptr) { @@ -287,7 +289,7 @@ Slice Slice::get(std::string const& attribute) const { if (!key.isEqualString(attribute)) { return Slice(); } - } else if (key.isInteger()) { + } else if (key.isSmallInt() || key.isUInt()) { // translate key if (!key.translate().isEqualString(attribute)) { return Slice(); @@ -435,7 +437,7 @@ Slice Slice::getFromCompactObject(std::string const& attribute) const { if (key.isEqualString(attribute)) { return Slice(key.start() + key.byteSize(), options); } - } else if (key.isInteger()) { + } else if (key.isSmallInt() || key.isUInt()) { if (key.translate().isEqualString(attribute)) { return Slice(key.start() + key.byteSize(), options); } @@ -536,7 +538,7 @@ Slice Slice::makeKey() const { if (isString()) { return *this; } - if (isInteger()) { + if (isSmallInt() || isUInt()) { return translate(); } @@ -580,7 +582,7 @@ Slice Slice::searchObjectKeyLinear(std::string const& attribute, if (!key.isEqualString(attribute)) { continue; } - } else if (key.isInteger()) { + } else if (key.isSmallInt() || key.isUInt()) { // translate key if (!key.translate().isEqualString(attribute)) { continue; @@ -618,7 +620,7 @@ Slice Slice::searchObjectKeyBinary(std::string const& attribute, int res; if (key.isString()) { res = key.compareString(attribute); - } else if (key.isInteger()) { + } else if (key.isSmallInt() || key.isUInt()) { // translate key res = key.translate().compareString(attribute); } else { diff --git a/3rdParty/velocypack/src/fpconv.cpp b/3rdParty/velocypack/src/fpconv.cpp index 12cd852c2c..74302e5a62 100644 --- a/3rdParty/velocypack/src/fpconv.cpp +++ b/3rdParty/velocypack/src/fpconv.cpp @@ -47,12 +47,9 @@ int fpconv_dtoa(double fp, char dest[24]); static uint64_t tens[] = { 10000000000000000000U, 1000000000000000000U, 100000000000000000U, - 10000000000000000U, 1000000000000000U, 100000000000000U, - 10000000000000U, 1000000000000U, 100000000000U, - 10000000000U, 1000000000U, 100000000U, - 10000000U, 1000000U, 100000U, - 10000U, 1000U, 100U, - 10U, 1U}; + 10000000000000000U, 1000000000000000U, 100000000000000U, 10000000000000U, + 1000000000000U, 100000000000U, 10000000000U, 1000000000U, 100000000U, + 10000000U, 1000000U, 100000U, 10000U, 1000U, 100U, 10U, 1U}; static inline uint64_t get_dbits(double d) { union {