diff options
8 files changed, 76 insertions, 74 deletions
diff --git a/storage/src/vespa/storage/visiting/countvisitor.cpp b/storage/src/vespa/storage/visiting/countvisitor.cpp index b8b415402d6..fe1569f84da 100644 --- a/storage/src/vespa/storage/visiting/countvisitor.cpp +++ b/storage/src/vespa/storage/visiting/countvisitor.cpp @@ -26,10 +26,9 @@ CountVisitor::handleDocuments(const document::BucketId& /*bucketId*/, DocEntryList& entries, HitCounter& hitCounter) { - for (size_t i = 0; i < entries.size(); ++i) { - const spi::DocEntry& entry(*entries[i]); - if (!entry.isRemove()) { - const document::Document* doc = entry.getDocument(); + for (const auto & entry : entries) { + if (!entry->isRemove()) { + const document::Document* doc = entry->getDocument(); if (doc) { const document::IdString& idString = doc->getId().getScheme(); @@ -57,33 +56,25 @@ CountVisitor::handleDocuments(const document::BucketId& /*bucketId*/, } void CountVisitor::completedVisiting(HitCounter&) { - documentapi::MapVisitorMessage* cmd(new documentapi::MapVisitorMessage()); + auto cmd = std::make_unique<documentapi::MapVisitorMessage>(); - for (std::map<std::string, int>::iterator iter = _schemeCount.begin(); - iter != _schemeCount.end(); - iter++) { - cmd->getData().set(vespalib::make_string("scheme.%s", iter->first.c_str()), iter->second); + for (const auto & count : _schemeCount) { + cmd->getData().set(vespalib::make_string("scheme.%s", count.first.c_str()), count.second); } - for (NamespaceCountMap::const_iterator iter = _namespaceCount.begin(); - iter != _namespaceCount.end(); - iter++) { - cmd->getData().set(vespalib::make_string("namespace.%s", iter->first.c_str()), iter->second); + for (const auto & count : _namespaceCount) { + cmd->getData().set(vespalib::make_string("namespace.%s", count.first.c_str()), count.second); } - for (GroupCountMap::const_iterator iter = _groupCount.begin(); - iter != _groupCount.end(); - iter++) { - cmd->getData().set(vespalib::make_string("group.%s", iter->first.c_str()), iter->second); + for (const auto & count : _groupCount) { + cmd->getData().set(vespalib::make_string("group.%s", count.first.c_str()), count.second); } - for (std::map<uint64_t, int>::iterator iter = _userCount.begin(); - iter != _userCount.end(); - iter++) { - cmd->getData().set(vespalib::make_string("user.%" PRIu64, iter->first), iter->second); + for (const auto & count : _userCount) { + cmd->getData().set(vespalib::make_string("user.%" PRIu64, count.first), count.second); } - sendMessage(documentapi::DocumentMessage::UP(cmd)); + sendMessage(std::move(cmd)); } } diff --git a/storage/src/vespa/storageapi/mbusprot/protocolserialization7.cpp b/storage/src/vespa/storageapi/mbusprot/protocolserialization7.cpp index efbe8c9b42d..57047be6037 100644 --- a/storage/src/vespa/storageapi/mbusprot/protocolserialization7.cpp +++ b/storage/src/vespa/storageapi/mbusprot/protocolserialization7.cpp @@ -56,8 +56,8 @@ void set_bucket_info(protobuf::BucketInfo& dest, const api::BucketInfo& src) { } document::Bucket get_bucket(const protobuf::Bucket& src) { - return document::Bucket(document::BucketSpace(src.space_id()), - document::BucketId(src.raw_bucket_id())); + return {document::BucketSpace(src.space_id()), + document::BucketId(src.raw_bucket_id())}; } api::BucketInfo get_bucket_info(const protobuf::BucketInfo& src) { @@ -953,11 +953,11 @@ void fill_api_apply_diff_vector(std::vector<api::ApplyBucketDiffCommand::Entry>& dest._docName = proto_entry.document_id(); // TODO consider making buffers std::strings instead to avoid explicit zeroing-on-resize overhead dest._headerBlob.resize(proto_entry.header_blob().size()); - if (proto_entry.header_blob().size() > 0) { + if (!proto_entry.header_blob().empty()) { memcpy(dest._headerBlob.data(), proto_entry.header_blob().data(), proto_entry.header_blob().size()); } dest._bodyBlob.resize(proto_entry.body_blob().size()); - if (proto_entry.body_blob().size() > 0) { + if (!proto_entry.body_blob().empty()) { memcpy(dest._bodyBlob.data(), proto_entry.body_blob().data(), proto_entry.body_blob().size()); } } diff --git a/storage/src/vespa/storageapi/message/datagram.cpp b/storage/src/vespa/storageapi/message/datagram.cpp index d2ced1d4b7b..103b7ead08c 100644 --- a/storage/src/vespa/storageapi/message/datagram.cpp +++ b/storage/src/vespa/storageapi/message/datagram.cpp @@ -5,8 +5,7 @@ using document::BucketSpace; -namespace storage { -namespace api { +namespace storage::api { IMPLEMENT_COMMAND(MapVisitorCommand, MapVisitorReply) IMPLEMENT_REPLY(MapVisitorReply) @@ -24,11 +23,9 @@ MapVisitorCommand::print(std::ostream& out, bool verbose, { out << "MapVisitor(" << _statistics.size() << " entries"; if (verbose) { - for (vdslib::Parameters::ParametersMap::const_iterator it - = _statistics.begin(); it != _statistics.end(); ++it) - { - out << ",\n" << indent << " " << it->first << ": " - << vespalib::stringref(it->second.c_str(), it->second.length()); + for (const auto & stat : _statistics) { + out << ",\n" << indent << " " << stat.first << ": " + << vespalib::stringref(stat.second.c_str(), stat.second.length()); } out << ") : "; StorageCommand::print(out, verbose, indent); @@ -66,9 +63,9 @@ EmptyBucketsCommand::print(std::ostream& out, bool verbose, { out << "EmptyBuckets("; if (verbose) { - for (uint32_t i=0; i<_buckets.size(); ++i) { + for (const auto & bucket : _buckets) { out << "\n" << indent << " "; - out << _buckets[i]; + out << bucket; } } else { out << _buckets.size() << " buckets"; @@ -96,5 +93,4 @@ EmptyBucketsReply::print(std::ostream& out, bool verbose, } } -} // api -} // storage +} diff --git a/storage/src/vespa/storageapi/message/visitor.h b/storage/src/vespa/storageapi/message/visitor.h index fddb7604eff..979b8064bd8 100644 --- a/storage/src/vespa/storageapi/message/visitor.h +++ b/storage/src/vespa/storageapi/message/visitor.h @@ -58,7 +58,7 @@ public: /** Create another command with similar visitor settings. */ CreateVisitorCommand(const CreateVisitorCommand& template_); - ~CreateVisitorCommand(); + ~CreateVisitorCommand() override; void setVisitorCmdId(uint32_t id) { _visitorCmdId = id; } void setControlDestination(vespalib::stringref d) { _controlDestination = d; } @@ -211,7 +211,7 @@ public: void setErrorCode(ReturnCode && code) { _error = std::move(code); } void setCompleted() { _completed = true; } void setBucketCompleted(const document::BucketId& id, Timestamp lastVisited) { - _bucketsCompleted.push_back(BucketTimestampPair(id, lastVisited)); + _bucketsCompleted.emplace_back(id, lastVisited); } void setBucketsCompleted(const std::vector<BucketTimestampPair>& bc) { _bucketsCompleted = bc; @@ -234,7 +234,7 @@ class VisitorInfoReply : public StorageReply { bool _completed; public: - VisitorInfoReply(const VisitorInfoCommand& cmd); + explicit VisitorInfoReply(const VisitorInfoCommand& cmd); bool visitorCompleted() const { return _completed; } void print(std::ostream& out, bool verbose, const std::string& indent) const override; diff --git a/streamingvisitors/src/vespa/vsm/searcher/floatfieldsearcher.cpp b/streamingvisitors/src/vespa/vsm/searcher/floatfieldsearcher.cpp index 7dd40348f47..8558522003f 100644 --- a/streamingvisitors/src/vespa/vsm/searcher/floatfieldsearcher.cpp +++ b/streamingvisitors/src/vespa/vsm/searcher/floatfieldsearcher.cpp @@ -37,7 +37,7 @@ void FloatFieldSearcherT<T>::prepare(search::streaming::QueryTermList& qtl, _floatTerm.clear(); FieldSearcher::prepare(qtl, buf, field_paths, query_env); for (auto qt : qtl) { - size_t sz(qt->termLen()); + size_t sz(qt->termLen()); if (sz) { auto range = qt->getRange<T>(); _floatTerm.emplace_back(range.low, range.high, range.valid); diff --git a/vdslib/src/vespa/vdslib/container/parameters.cpp b/vdslib/src/vespa/vdslib/container/parameters.cpp index 298f4f6c0d8..236b4970396 100644 --- a/vdslib/src/vespa/vdslib/container/parameters.cpp +++ b/vdslib/src/vespa/vdslib/container/parameters.cpp @@ -7,6 +7,7 @@ #include <vespa/vespalib/util/xmlstream.h> #include <vespa/vespalib/util/growablebytebuffer.h> #include <ostream> +#include <charconv> using namespace vdslib; @@ -137,13 +138,35 @@ vespalib::string Parameters::toString() const return ret; } -template void vdslib::Parameters::set(vespalib::stringref , int32_t); -template void vdslib::Parameters::set(vespalib::stringref , int64_t); -template void vdslib::Parameters::set(vespalib::stringref , uint64_t); -template void vdslib::Parameters::set(vespalib::stringref , double); -template void vdslib::Parameters::set(vespalib::stringref , const char *); -template void vdslib::Parameters::set(vespalib::stringref , vespalib::string); -template void vdslib::Parameters::set(vespalib::stringref , std::string); +void +Parameters::set(KeyT id, int32_t value) { + char tmp[16]; + auto res = std::to_chars(tmp, tmp + sizeof(tmp), value, 10); + _parameters[id] = Value(tmp, size_t(res.ptr - tmp)); +} + +void +Parameters::set(KeyT id, int64_t value) { + char tmp[32]; + auto res = std::to_chars(tmp, tmp + sizeof(tmp), value, 10); + _parameters[id] = Value(tmp, size_t(res.ptr - tmp)); +} + +void +Parameters::set(KeyT id, uint64_t value) { + char tmp[32]; + auto res = std::to_chars(tmp, tmp + sizeof(tmp), value, 10); + _parameters[id] = Value(tmp, size_t(res.ptr - tmp)); +} + +void +Parameters::set(KeyT id, double value) { + vespalib::asciistream ost; + ost << value; + _parameters[id] = Value(ost.str()); +} + + template int32_t vdslib::Parameters::get(vespalib::stringref , int32_t) const; template int64_t vdslib::Parameters::get(vespalib::stringref , int64_t) const; template uint64_t vdslib::Parameters::get(vespalib::stringref , uint64_t) const; diff --git a/vdslib/src/vespa/vdslib/container/parameters.h b/vdslib/src/vespa/vdslib/container/parameters.h index 854aec4be20..d28e2cd9890 100644 --- a/vdslib/src/vespa/vdslib/container/parameters.h +++ b/vdslib/src/vespa/vdslib/container/parameters.h @@ -28,11 +28,11 @@ public: class Value : public vespalib::string { public: - Value() { } - Value(vespalib::stringref s) : vespalib::string(s) { } - Value(const vespalib::string & s) : vespalib::string(s) { } - Value(const void *v, size_t sz) : vespalib::string(v, sz) { } - size_t length() const { return size() - 1; } + Value() = default; + explicit Value(vespalib::stringref s) noexcept : vespalib::string(s) { } + explicit Value(const vespalib::string & s) noexcept : vespalib::string(s) { } + Value(const void *v, size_t sz) noexcept : vespalib::string(v, sz) { } + size_t length() const noexcept { return size() - 1; } }; using ValueRef = vespalib::stringref; using ParametersMap = vespalib::hash_map<vespalib::string, Value>; @@ -43,8 +43,8 @@ private: public: Parameters(); - Parameters(document::ByteBuffer& buffer); - ~Parameters(); + explicit Parameters(document::ByteBuffer& buffer); + ~Parameters() override; bool operator==(const Parameters &other) const; @@ -53,7 +53,9 @@ public: bool hasValue(KeyT id) const { return (_parameters.find(id) != _parameters.end()); } unsigned int size() const { return _parameters.size(); } bool lookup(KeyT id, ValueRef & v) const; - void set(KeyT id, const void * v, size_t sz) { _parameters[id] = Value(v, sz); } + void set(KeyT id, const void * v, size_t sz) { + _parameters[id] = Value(v, sz); + } void print(std::ostream& out, bool verbose, const std::string& indent) const; void serialize(vespalib::GrowableByteBuffer& buffer) const; @@ -63,17 +65,15 @@ public: ParametersMap::const_iterator begin() const { return _parameters.begin(); } ParametersMap::const_iterator end() const { return _parameters.end(); } /// Convenience from earlier use. - void set(KeyT id, vespalib::stringref value) { _parameters[id] = Value(value.data(), value.size()); } + void set(KeyT id, vespalib::stringref value) { + _parameters[id] = Value(value.data(), value.size()); + } + void set(KeyT id, int32_t value); + void set(KeyT id, int64_t value); + void set(KeyT id, uint64_t value); + void set(KeyT id, double value); vespalib::stringref get(KeyT id, vespalib::stringref def = "") const; - /** - * Set the value identified by the id given. This requires the type to be - * convertible by stringstreams. - * - * @param id The value to get. - * @param t The value to save. Will be converted to a string. - */ - template<typename T> - void set(KeyT id, T t); + /** * Get the value identified by the id given, as the same type as the default diff --git a/vdslib/src/vespa/vdslib/container/parameters.hpp b/vdslib/src/vespa/vdslib/container/parameters.hpp index ae5706046d4..d91612bc094 100644 --- a/vdslib/src/vespa/vdslib/container/parameters.hpp +++ b/vdslib/src/vespa/vdslib/container/parameters.hpp @@ -7,14 +7,6 @@ namespace vdslib { template<typename T> -void -Parameters::set(KeyT id, T t) { - vespalib::asciistream ost; - ost << t; - _parameters[id] = ost.str(); -} - -template<typename T> T Parameters::get(KeyT id, T def) const { vespalib::stringref ref; |