diff options
author | Henning Baldersheim <balder@yahoo-inc.com> | 2017-07-27 11:44:39 +0200 |
---|---|---|
committer | Henning Baldersheim <balder@yahoo-inc.com> | 2017-07-31 17:27:02 +0200 |
commit | 157ff8c0b62477efeea1947b80ad62c54a51decc (patch) | |
tree | f825f2990bdaf18983f58ca0560c6e73fcf99a1b /document | |
parent | 61857dbdbffcdc116ab9a365a95e1da131fe7a89 (diff) |
Use noexcept to get move constructor usage on containers and use fastCompare.
Diffstat (limited to 'document')
10 files changed, 59 insertions, 39 deletions
diff --git a/document/src/vespa/document/base/fieldpath.cpp b/document/src/vespa/document/base/fieldpath.cpp index 2af7a6315f7..abed9ec4816 100644 --- a/document/src/vespa/document/base/fieldpath.cpp +++ b/document/src/vespa/document/base/fieldpath.cpp @@ -178,28 +178,11 @@ FieldPath::FieldPath(const FieldPath &) = default; FieldPath & FieldPath::operator=(const FieldPath &) = default; FieldPath::~FieldPath() { } -FieldPath::iterator -FieldPath::insert(iterator pos, FieldPathEntry && entry) -{ - return _path.insert(pos, std::move(entry)); -} -void -FieldPath::push_back(FieldPathEntry && entry) -{ - _path.push_back(std::move(entry)); -} - -void -FieldPath::pop_back() -{ - _path.pop_back(); -} - -void -FieldPath::clear() -{ - _path.clear(); -} +FieldPath::iterator FieldPath::insert(iterator pos, FieldPathEntry && entry) { return _path.insert(pos, std::move(entry)); } +void FieldPath::push_back(FieldPathEntry && entry) { _path.push_back(std::move(entry)); } +void FieldPath::pop_back() { _path.pop_back(); } +void FieldPath::clear() { _path.clear(); } +void FieldPath::reserve(size_t sz) { _path.reserve(sz); } void FieldPath::visitMembers(vespalib::ObjectVisitor& visitor) const diff --git a/document/src/vespa/document/base/fieldpath.h b/document/src/vespa/document/base/fieldpath.h index 22fa1979427..5c0a3553e3b 100644 --- a/document/src/vespa/document/base/fieldpath.h +++ b/document/src/vespa/document/base/fieldpath.h @@ -35,8 +35,8 @@ public: */ FieldPathEntry(); - FieldPathEntry(FieldPathEntry &&) = default; - FieldPathEntry & operator=(FieldPathEntry &&) = default; + FieldPathEntry(FieldPathEntry &&) noexcept = default; + FieldPathEntry & operator=(FieldPathEntry &&) noexcept = default; FieldPathEntry(const FieldPathEntry &); FieldPathEntry & operator=(const FieldPathEntry &); @@ -147,6 +147,7 @@ public: void pop_back(); void clear(); + void reserve(size_t sz); Container::size_type size() const { return _path.size(); } bool empty() const { return _path.empty(); } diff --git a/document/src/vespa/document/datatype/datatype.cpp b/document/src/vespa/document/datatype/datatype.cpp index ede084f8962..9083a5352ff 100644 --- a/document/src/vespa/document/datatype/datatype.cpp +++ b/document/src/vespa/document/datatype/datatype.cpp @@ -174,6 +174,7 @@ void DataType::buildFieldPath(FieldPath & path, const vespalib::stringref & remainFieldName) const { if ( !remainFieldName.empty() ) { + path.reserve(4); // Optimize for short paths onBuildFieldPath(path,remainFieldName); } } diff --git a/document/src/vespa/document/fieldvalue/fieldvalue.cpp b/document/src/vespa/document/fieldvalue/fieldvalue.cpp index d3109160248..44de51e7fe1 100644 --- a/document/src/vespa/document/fieldvalue/fieldvalue.cpp +++ b/document/src/vespa/document/fieldvalue/fieldvalue.cpp @@ -74,6 +74,11 @@ FieldValue::compare(const FieldValue& other) const { : 0; } +int +FieldValue::fastCompare(const FieldValue& other) const { + return compare(other); +} + FieldValue& FieldValue::assign(const FieldValue& value) { diff --git a/document/src/vespa/document/fieldvalue/fieldvalue.h b/document/src/vespa/document/fieldvalue/fieldvalue.h index 73e0acc81a3..0f7e1fb432c 100644 --- a/document/src/vespa/document/fieldvalue/fieldvalue.h +++ b/document/src/vespa/document/fieldvalue/fieldvalue.h @@ -84,6 +84,13 @@ public: virtual int compare(const FieldValue& other) const; /** + * Same as normal compar, but this one expects the types to be equal + * @param other + * @return See compare + */ + virtual int fastCompare(const FieldValue& other) const; + + /** * Returns true if this object have been altered since last * serialization/deserialization. If hasChanged() is false, then cached * information from last serialization effort is still valid. diff --git a/document/src/vespa/document/fieldvalue/literalfieldvalue.cpp b/document/src/vespa/document/fieldvalue/literalfieldvalue.cpp index b5e0a4eb099..747c789c6cd 100644 --- a/document/src/vespa/document/fieldvalue/literalfieldvalue.cpp +++ b/document/src/vespa/document/fieldvalue/literalfieldvalue.cpp @@ -63,13 +63,19 @@ int LiteralFieldValueB::compare(const FieldValue& other) const { if (*getDataType() == *other.getDataType()) { - const LiteralFieldValueB& sval( - static_cast<const LiteralFieldValueB&>(other)); + const LiteralFieldValueB& sval(static_cast<const LiteralFieldValueB&>(other)); return getValueRef().compare(sval.getValueRef()); } return (getDataType()->getId() - other.getDataType()->getId()); } +int +LiteralFieldValueB::fastCompare(const FieldValue& other) const +{ + const LiteralFieldValueB& sval(static_cast<const LiteralFieldValueB&>(other)); + return getValueRef().compare(sval.getValueRef()); +} + void LiteralFieldValueB::printXml(XmlOutputStream& out) const { diff --git a/document/src/vespa/document/fieldvalue/literalfieldvalue.h b/document/src/vespa/document/fieldvalue/literalfieldvalue.h index ca09acedcd3..57bfae2bcd3 100644 --- a/document/src/vespa/document/fieldvalue/literalfieldvalue.h +++ b/document/src/vespa/document/fieldvalue/literalfieldvalue.h @@ -58,13 +58,13 @@ public: void setValue(const char* val, size_t size) { setValue(stringref(val, size)); } int compare(const FieldValue& other) const override; + int fastCompare(const FieldValue& other) const override; vespalib::string getAsString() const override; std::pair<const char*, size_t> getAsRaw() const override; void printXml(XmlOutputStream& out) const override; - void print(std::ostream& out, bool verbose, - const std::string& indent) const override; + void print(std::ostream& out, bool verbose, const std::string& indent) const override; FieldValue& assign(const FieldValue&) override; bool hasChanged() const override{ return _altered; } diff --git a/document/src/vespa/document/fieldvalue/mapfieldvalue.cpp b/document/src/vespa/document/fieldvalue/mapfieldvalue.cpp index 2b0463d39e6..3a294fa1fb4 100644 --- a/document/src/vespa/document/fieldvalue/mapfieldvalue.cpp +++ b/document/src/vespa/document/fieldvalue/mapfieldvalue.cpp @@ -252,9 +252,12 @@ MapFieldValue::hasChanged() const MapFieldValue::const_iterator MapFieldValue::find(const FieldValue& key) const { - for(size_t i(0), m(_keys->size()); i < m; i++) { - if ((*_keys)[i] == key) { - return const_iterator(*this, i); + size_t sz = _keys->size(); + if ((sz > 0) && (key.getClass().id() == (*_keys)[0].getClass().id())) { + for (size_t i(0), m(_keys->size()); i < m; i++) { + if ((*_keys)[i].fastCompare(key) == 0) { + return const_iterator(*this, i); + } } } return end(); @@ -263,17 +266,18 @@ MapFieldValue::find(const FieldValue& key) const MapFieldValue::iterator MapFieldValue::find(const FieldValue& key) { - for(size_t i(0), m(_keys->size()); i < m; i++) { - if ((*_keys)[i] == key) { - return iterator(*this, i); + size_t sz = _keys->size(); + if ((sz > 0) && (key.getClass().id() == (*_keys)[0].getClass().id())) { + for (size_t i(0), m(_keys->size()); i < m; i++) { + if ((*_keys)[i].fastCompare(key) == 0) { + return iterator(*this, i); + } } } return end(); } bool -MapFieldValue::checkAndRemove(const FieldValue& key, - ModificationStatus status, - bool wasModified, +MapFieldValue::checkAndRemove(const FieldValue& key, ModificationStatus status, bool wasModified, std::vector<const FieldValue*>& keysToRemove) const { if (status == ModificationStatus::REMOVED) { diff --git a/document/src/vespa/document/fieldvalue/numericfieldvalue.h b/document/src/vespa/document/fieldvalue/numericfieldvalue.h index f70c9a33492..d119778eef4 100644 --- a/document/src/vespa/document/fieldvalue/numericfieldvalue.h +++ b/document/src/vespa/document/fieldvalue/numericfieldvalue.h @@ -38,6 +38,7 @@ public: FieldValue& assign(const FieldValue&) override ; int compare(const FieldValue& other) const override; + int fastCompare(const FieldValue& other) const override; FieldValue& operator=(const vespalib::stringref &) override; FieldValue& operator=(int32_t) override; diff --git a/document/src/vespa/document/fieldvalue/numericfieldvalue.hpp b/document/src/vespa/document/fieldvalue/numericfieldvalue.hpp index 99980e251f5..881cdb4a7e3 100644 --- a/document/src/vespa/document/fieldvalue/numericfieldvalue.hpp +++ b/document/src/vespa/document/fieldvalue/numericfieldvalue.hpp @@ -53,9 +53,21 @@ NumericFieldValue<Number>::compare( const FieldValue& other) const } template<typename Number> +int +NumericFieldValue<Number>::fastCompare( const FieldValue& other) const +{ + + const NumericFieldValue & otherNumber(static_cast<const NumericFieldValue &>(other)); + return (_value == otherNumber._value) + ? 0 + : (_value - otherNumber._value > 0) + ? 1 + : -1; +} + +template<typename Number> void -NumericFieldValue<Number>::print( - std::ostream& out, bool, const std::string&) const +NumericFieldValue<Number>::print(std::ostream& out, bool, const std::string&) const { if (sizeof(Number) == 1) { // Make sure char's are printed as numbers out << (int) _value; |