summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorHenning Baldersheim <balder@yahoo-inc.com>2024-01-02 19:35:09 +0100
committerGitHub <noreply@github.com>2024-01-02 19:35:09 +0100
commit16a9a6cacefb90fce4a49150fd8220afc22599a9 (patch)
treecb86e1f4ca3e3f83626f41ef11e64fdb81b8c9be
parentf031666ee60ab878782bc4490aa697635c43026d (diff)
parent008d81c1f2aee5498472f0aab1c20724c1b7f9b2 (diff)
Merge pull request #29755 from vespa-engine/balder/avoid-generic-template
- Avoid inefficient generic template.
-rw-r--r--searchlib/src/vespa/searchlib/query/streaming/query.cpp10
-rw-r--r--searchlib/src/vespa/searchlib/query/streaming/query.h31
-rw-r--r--searchlib/src/vespa/searchlib/query/streaming/querynode.cpp38
-rw-r--r--searchlib/src/vespa/searchlib/query/streaming/querynode.h2
-rw-r--r--searchlib/src/vespa/searchlib/query/streaming/querynoderesultbase.h2
-rw-r--r--searchlib/src/vespa/searchlib/query/streaming/queryterm.cpp9
-rw-r--r--searchlib/src/vespa/searchlib/query/streaming/queryterm.h2
-rw-r--r--storage/src/vespa/storage/visiting/countvisitor.cpp35
-rw-r--r--storage/src/vespa/storageapi/mbusprot/protocolserialization7.cpp8
-rw-r--r--storage/src/vespa/storageapi/message/datagram.cpp18
-rw-r--r--storage/src/vespa/storageapi/message/visitor.h6
-rw-r--r--streamingvisitors/src/vespa/vsm/searcher/floatfieldsearcher.cpp2
-rw-r--r--vdslib/src/vespa/vdslib/container/parameters.cpp37
-rw-r--r--vdslib/src/vespa/vdslib/container/parameters.h36
-rw-r--r--vdslib/src/vespa/vdslib/container/parameters.hpp8
15 files changed, 124 insertions, 120 deletions
diff --git a/searchlib/src/vespa/searchlib/query/streaming/query.cpp b/searchlib/src/vespa/searchlib/query/streaming/query.cpp
index d2eee5d345f..3079ec31e8f 100644
--- a/searchlib/src/vespa/searchlib/query/streaming/query.cpp
+++ b/searchlib/src/vespa/searchlib/query/streaming/query.cpp
@@ -12,7 +12,7 @@ QueryConnector::visitMembers(vespalib::ObjectVisitor &visitor) const
visit(visitor, "Operator", _opName);
}
-QueryConnector::QueryConnector(const char * opName)
+QueryConnector::QueryConnector(const char * opName) noexcept
: QueryNode(),
_opName(opName),
_index(),
@@ -31,7 +31,7 @@ const HitList &
QueryConnector::evaluateHits(HitList & hl) const
{
if (evaluate()) {
- hl.push_back(Hit(1, 0, 0, 1));
+ hl.emplace_back(1, 0, 0, 1);
}
return hl;
}
@@ -105,10 +105,10 @@ QueryConnector::create(ParseItem::ItemType type)
{
switch (type) {
case search::ParseItem::ITEM_AND: return std::make_unique<AndQueryNode>();
- case search::ParseItem::ITEM_OR: return std::make_unique<OrQueryNode>();
+ case search::ParseItem::ITEM_OR:
case search::ParseItem::ITEM_WEAK_AND: return std::make_unique<OrQueryNode>();
+ case search::ParseItem::ITEM_WEIGHTED_SET:
case search::ParseItem::ITEM_EQUIV: return std::make_unique<EquivQueryNode>();
- case search::ParseItem::ITEM_WEIGHTED_SET: return std::make_unique<EquivQueryNode>();
case search::ParseItem::ITEM_WAND: return std::make_unique<OrQueryNode>();
case search::ParseItem::ITEM_NOT: return std::make_unique<AndNotQueryNode>();
case search::ParseItem::ITEM_PHRASE: return std::make_unique<PhraseQueryNode>();
@@ -340,7 +340,7 @@ Query::Query(const QueryNodeResultFactory & factory, vespalib::stringref queryRe
bool
Query::evaluate() const {
- return valid() ? _root->evaluate() : false;
+ return valid() && _root->evaluate();
}
bool
diff --git a/searchlib/src/vespa/searchlib/query/streaming/query.h b/searchlib/src/vespa/searchlib/query/streaming/query.h
index 42c3b94002c..3904f743d26 100644
--- a/searchlib/src/vespa/searchlib/query/streaming/query.h
+++ b/searchlib/src/vespa/searchlib/query/streaming/query.h
@@ -13,8 +13,8 @@ namespace search::streaming {
class QueryConnector : public QueryNode
{
public:
- QueryConnector(const char * opName);
- ~QueryConnector();
+ explicit QueryConnector(const char * opName) noexcept;
+ ~QueryConnector() override;
const HitList & evaluateHits(HitList & hl) const override;
void reset() override;
void getLeaves(QueryTermList & tl) override;
@@ -44,7 +44,7 @@ private:
class TrueNode : public QueryConnector
{
public:
- TrueNode() : QueryConnector("AND") { }
+ TrueNode() noexcept : QueryConnector("AND") { }
bool evaluate() const override;
};
@@ -52,7 +52,7 @@ public:
class FalseNode : public QueryConnector
{
public:
- FalseNode() : QueryConnector("AND") { }
+ FalseNode() noexcept : QueryConnector("AND") { }
bool evaluate() const override;
};
@@ -62,8 +62,8 @@ public:
class AndQueryNode : public QueryConnector
{
public:
- AndQueryNode() : QueryConnector("AND") { }
- AndQueryNode(const char * opName) : QueryConnector(opName) { }
+ AndQueryNode() noexcept : QueryConnector("AND") { }
+ explicit AndQueryNode(const char * opName) noexcept : QueryConnector(opName) { }
bool evaluate() const override;
bool isFlattenable(ParseItem::ItemType type) const override { return type == ParseItem::ITEM_AND; }
};
@@ -74,7 +74,7 @@ public:
class AndNotQueryNode : public QueryConnector
{
public:
- AndNotQueryNode() : QueryConnector("ANDNOT") { }
+ AndNotQueryNode() noexcept : QueryConnector("ANDNOT") { }
bool evaluate() const override;
bool isFlattenable(ParseItem::ItemType type) const override { return type == ParseItem::ITEM_NOT; }
};
@@ -85,8 +85,8 @@ public:
class OrQueryNode : public QueryConnector
{
public:
- OrQueryNode() : QueryConnector("OR") { }
- OrQueryNode(const char * opName) : QueryConnector(opName) { }
+ OrQueryNode() noexcept : QueryConnector("OR") { }
+ explicit OrQueryNode(const char * opName) noexcept : QueryConnector(opName) { }
bool evaluate() const override;
bool isFlattenable(ParseItem::ItemType type) const override {
return (type == ParseItem::ITEM_OR) ||
@@ -102,7 +102,7 @@ public:
class EquivQueryNode : public OrQueryNode
{
public:
- EquivQueryNode() : OrQueryNode("EQUIV") { }
+ EquivQueryNode() noexcept : OrQueryNode("EQUIV") { }
bool evaluate() const override;
bool isFlattenable(ParseItem::ItemType type) const override {
return (type == ParseItem::ITEM_EQUIV) ||
@@ -117,7 +117,7 @@ public:
class PhraseQueryNode : public AndQueryNode
{
public:
- PhraseQueryNode() : AndQueryNode("PHRASE"), _fieldInfo(32) { }
+ PhraseQueryNode() noexcept : AndQueryNode("PHRASE"), _fieldInfo(32) { }
bool evaluate() const override;
const HitList & evaluateHits(HitList & hl) const override;
void getPhrases(QueryNodeRefList & tl) override;
@@ -138,7 +138,7 @@ private:
class SameElementQueryNode : public AndQueryNode
{
public:
- SameElementQueryNode() : AndQueryNode("SAME_ELEMENT") { }
+ SameElementQueryNode() noexcept : AndQueryNode("SAME_ELEMENT") { }
bool evaluate() const override;
const HitList & evaluateHits(HitList & hl) const override;
bool isFlattenable(ParseItem::ItemType type) const override { return type == ParseItem::ITEM_NOT; }
@@ -151,8 +151,8 @@ public:
class NearQueryNode : public AndQueryNode
{
public:
- NearQueryNode() : AndQueryNode("NEAR"), _distance(0) { }
- NearQueryNode(const char * opName) : AndQueryNode(opName), _distance(0) { }
+ NearQueryNode() noexcept : AndQueryNode("NEAR"), _distance(0) { }
+ explicit NearQueryNode(const char * opName) noexcept : AndQueryNode(opName), _distance(0) { }
bool evaluate() const override;
void distance(size_t dist) { _distance = dist; }
size_t distance() const { return _distance; }
@@ -169,8 +169,7 @@ private:
class ONearQueryNode : public NearQueryNode
{
public:
- ONearQueryNode() : NearQueryNode("ONEAR") { }
- ~ONearQueryNode() { }
+ ONearQueryNode() noexcept : NearQueryNode("ONEAR") { }
bool evaluate() const override;
};
diff --git a/searchlib/src/vespa/searchlib/query/streaming/querynode.cpp b/searchlib/src/vespa/searchlib/query/streaming/querynode.cpp
index db0fbd5b98e..6b3aa7a2fd0 100644
--- a/searchlib/src/vespa/searchlib/query/streaming/querynode.cpp
+++ b/searchlib/src/vespa/searchlib/query/streaming/querynode.cpp
@@ -13,12 +13,18 @@ LOG_SETUP(".vsm.querynode");
namespace search::streaming {
namespace {
- vespalib::stringref DEFAULT("default");
- bool disableRewrite(const QueryNode * qn) {
- return dynamic_cast<const NearQueryNode *> (qn) ||
- dynamic_cast<const PhraseQueryNode *> (qn) ||
- dynamic_cast<const SameElementQueryNode *>(qn);
- }
+
+vespalib::stringref DEFAULT("default");
+bool disableRewrite(const QueryNode * qn) {
+ return dynamic_cast<const NearQueryNode *> (qn) ||
+ dynamic_cast<const PhraseQueryNode *> (qn) ||
+ dynamic_cast<const SameElementQueryNode *>(qn);
+}
+
+bool possibleFloat(const QueryTerm & qt, const QueryTerm::string & term) {
+ return !qt.encoding().isBase10Integer() && qt.encoding().isFloat() && (term.find('.') != QueryTerm::string::npos);
+}
+
}
QueryNode::UP
@@ -43,8 +49,8 @@ QueryNode::Build(const QueryNode * parent, const QueryNodeResultFactory & factor
{
qn = QueryConnector::create(type);
if (qn) {
- QueryConnector * qc = dynamic_cast<QueryConnector *> (qn.get());
- NearQueryNode * nqn = dynamic_cast<NearQueryNode *> (qc);
+ auto * qc = dynamic_cast<QueryConnector *> (qn.get());
+ auto * nqn = dynamic_cast<NearQueryNode *> (qc);
if (nqn) {
nqn->distance(queryRep.getNearDistance());
}
@@ -150,21 +156,17 @@ QueryNode::Build(const QueryNode * parent, const QueryNodeResultFactory & factor
qt->setFuzzyMaxEditDistance(queryRep.getFuzzyMaxEditDistance());
qt->setFuzzyPrefixLength(queryRep.getFuzzyPrefixLength());
}
- if (qt->encoding().isBase10Integer() ||
- ! qt->encoding().isFloat() ||
- ! factory.getRewriteFloatTerms() ||
- ! allowRewrite ||
- (ssTerm.find('.') == vespalib::string::npos))
- {
- qn = std::move(qt);
- } else {
+ if (possibleFloat(*qt, ssTerm) && factory.getRewriteFloatTerms() && allowRewrite) {
auto phrase = std::make_unique<PhraseQueryNode>();
- phrase->addChild(std::make_unique<QueryTerm>(factory.create(), ssTerm.substr(0, ssTerm.find('.')), ssIndex, TermType::WORD));
- phrase->addChild(std::make_unique<QueryTerm>(factory.create(), ssTerm.substr(ssTerm.find('.') + 1), ssIndex, TermType::WORD));
+ auto dotPos = ssTerm.find('.');
+ phrase->addChild(std::make_unique<QueryTerm>(factory.create(), ssTerm.substr(0, dotPos), ssIndex, TermType::WORD));
+ phrase->addChild(std::make_unique<QueryTerm>(factory.create(), ssTerm.substr(dotPos + 1), ssIndex, TermType::WORD));
auto orqn = std::make_unique<EquivQueryNode>();
orqn->addChild(std::move(qt));
orqn->addChild(std::move(phrase));
qn = std::move(orqn);
+ } else {
+ qn = std::move(qt);
}
}
}
diff --git a/searchlib/src/vespa/searchlib/query/streaming/querynode.h b/searchlib/src/vespa/searchlib/query/streaming/querynode.h
index 09c44d951d3..bfc840e4603 100644
--- a/searchlib/src/vespa/searchlib/query/streaming/querynode.h
+++ b/searchlib/src/vespa/searchlib/query/streaming/querynode.h
@@ -36,7 +36,7 @@ class QueryNode
public:
using UP = std::unique_ptr<QueryNode>;
- virtual ~QueryNode() { }
+ virtual ~QueryNode() = default;
/// This evalutes if the subtree starting here evaluates to true.
virtual bool evaluate() const = 0;
/// This return the hitList for this subtree. Does only give meaning in a
diff --git a/searchlib/src/vespa/searchlib/query/streaming/querynoderesultbase.h b/searchlib/src/vespa/searchlib/query/streaming/querynoderesultbase.h
index 62fc32a4575..10f3b7cbf21 100644
--- a/searchlib/src/vespa/searchlib/query/streaming/querynoderesultbase.h
+++ b/searchlib/src/vespa/searchlib/query/streaming/querynoderesultbase.h
@@ -21,7 +21,7 @@ class QueryNodeResultFactory {
public:
virtual ~QueryNodeResultFactory() = default;
virtual bool getRewriteFloatTerms() const { return false; }
- virtual std::unique_ptr<QueryNodeResultBase> create() const { return std::unique_ptr<QueryNodeResultBase>(); }
+ virtual std::unique_ptr<QueryNodeResultBase> create() const { return {}; }
};
}
diff --git a/searchlib/src/vespa/searchlib/query/streaming/queryterm.cpp b/searchlib/src/vespa/searchlib/query/streaming/queryterm.cpp
index 9c45427d07d..a658ff5f3d6 100644
--- a/searchlib/src/vespa/searchlib/query/streaming/queryterm.cpp
+++ b/searchlib/src/vespa/searchlib/query/streaming/queryterm.cpp
@@ -15,6 +15,7 @@ private:
};
CharInfo::CharInfo()
+ : _charInfo()
{
// XXX: Should refactor to reduce number of magic constants.
memset(_charInfo, 0x01, 128); // All 7 bits are ascii7bit
@@ -33,7 +34,7 @@ CharInfo::CharInfo()
_charInfo[uint8_t('E')] = 0x05;
}
-static CharInfo _G_charTable;
+CharInfo _G_charTable;
}
@@ -65,10 +66,10 @@ QueryTerm::QueryTerm(std::unique_ptr<QueryNodeResultBase> org, const string & te
{
if (!termS.empty()) {
uint8_t enc(0xff);
- for (size_t i(0), m(termS.size()); i < m; i++) {
- enc &= _G_charTable.get(termS[i]);
+ for (char c : termS) {
+ enc &= _G_charTable.get(c);
}
- _encoding = enc;
+ _encoding = EncodingBitMap(enc);
}
}
diff --git a/searchlib/src/vespa/searchlib/query/streaming/queryterm.h b/searchlib/src/vespa/searchlib/query/streaming/queryterm.h
index 6e91437b1f9..2d1156a9c51 100644
--- a/searchlib/src/vespa/searchlib/query/streaming/queryterm.h
+++ b/searchlib/src/vespa/searchlib/query/streaming/queryterm.h
@@ -27,7 +27,7 @@ public:
class EncodingBitMap
{
public:
- EncodingBitMap(uint8_t bm=0) : _enc(bm) { }
+ explicit EncodingBitMap(uint8_t bm) : _enc(bm) { }
bool isFloat() const { return _enc & Float; }
bool isBase10Integer() const { return _enc & Base10Integer; }
bool isAscii7Bit() const { return _enc & Ascii7Bit; }
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;