summaryrefslogtreecommitdiffstats
path: root/searchlib
diff options
context:
space:
mode:
authorHenning Baldersheim <balder@yahoo-inc.com>2021-03-28 14:42:45 +0000
committerHenning Baldersheim <balder@yahoo-inc.com>2021-03-28 14:42:45 +0000
commitae90624a1574db2be4062fcb0546996abc2be19b (patch)
tree15bcb65633390dcbd0a1099a6a79ab6978c42b02 /searchlib
parentcd9645f8ee72eb99b9453773fb0e51b00cdcc9ef (diff)
- Use faster std::to_chars.
- Reorganize stackdumpitertor so members accesses frequently are colocated. - Add test to keep iteratorsize under control.
Diffstat (limited to 'searchlib')
-rw-r--r--searchlib/src/tests/attribute/bitvector/bitvector_test.cpp2
-rw-r--r--searchlib/src/tests/query/querybuilder_test.cpp4
-rw-r--r--searchlib/src/tests/query/stackdumpquerycreator_test.cpp3
-rw-r--r--searchlib/src/vespa/searchlib/attribute/i_document_weight_attribute.h2
-rw-r--r--searchlib/src/vespa/searchlib/diskindex/diskindex.cpp4
-rw-r--r--searchlib/src/vespa/searchlib/parsequery/stackdumpiterator.cpp61
-rw-r--r--searchlib/src/vespa/searchlib/parsequery/stackdumpiterator.h41
-rw-r--r--searchlib/src/vespa/searchlib/query/tree/stackdumpquerycreator.h2
8 files changed, 57 insertions, 62 deletions
diff --git a/searchlib/src/tests/attribute/bitvector/bitvector_test.cpp b/searchlib/src/tests/attribute/bitvector/bitvector_test.cpp
index bba266ca06e..3bf16aa3e7e 100644
--- a/searchlib/src/tests/attribute/bitvector/bitvector_test.cpp
+++ b/searchlib/src/tests/attribute/bitvector/bitvector_test.cpp
@@ -488,7 +488,7 @@ BitVectorTest::test(BasicType bt,
!filter, true);
const search::IDocumentWeightAttribute *dwa =
v->asDocumentWeightAttribute();
- if (dwa != NULL) {
+ if (dwa != nullptr) {
search::IDocumentWeightAttribute::LookupResult lres =
dwa->lookup(getSearchStr<VectorType>(), dwa->get_dictionary_snapshot());
typedef search::queryeval::DocumentWeightSearchIterator DWSI;
diff --git a/searchlib/src/tests/query/querybuilder_test.cpp b/searchlib/src/tests/query/querybuilder_test.cpp
index 30b4d2ae264..f1207da727d 100644
--- a/searchlib/src/tests/query/querybuilder_test.cpp
+++ b/searchlib/src/tests/query/querybuilder_test.cpp
@@ -592,6 +592,10 @@ TEST("require that empty intermediate node can be added") {
EXPECT_EQUAL(0u, and_node->getChildren().size());
}
+TEST("control size of SimpleQueryStackDumpIterator") {
+ EXPECT_EQUAL(160u, sizeof(SimpleQueryStackDumpIterator));
+}
+
TEST("test query parsing error") {
const char * STACK =
"\001\002\001\003\000\005\002\004\001\034F\001\002\004term\004\004term\002dx\004\004term\002ifD\002\004term\001xD\003\004term\002dxE\004\004term\001\060F\005\002\004term"
diff --git a/searchlib/src/tests/query/stackdumpquerycreator_test.cpp b/searchlib/src/tests/query/stackdumpquerycreator_test.cpp
index cb3989387b7..c5ef71621d1 100644
--- a/searchlib/src/tests/query/stackdumpquerycreator_test.cpp
+++ b/searchlib/src/tests/query/stackdumpquerycreator_test.cpp
@@ -48,8 +48,7 @@ TEST("requireThatTooLargeNumTermIsTreatedAsFloat") {
appendNumTerm(buf, term_string);
SimpleQueryStackDumpIterator query_stack(vespalib::stringref(buf.GetDrainPos(), buf.GetUsedLen()));
- Node::UP node =
- StackDumpQueryCreator<SimpleQueryNodeTypes>::create(query_stack);
+ Node::UP node = StackDumpQueryCreator<SimpleQueryNodeTypes>::create(query_stack);
ASSERT_TRUE(node.get());
NumberTerm *term = dynamic_cast<NumberTerm *>(node.get());
ASSERT_TRUE(term);
diff --git a/searchlib/src/vespa/searchlib/attribute/i_document_weight_attribute.h b/searchlib/src/vespa/searchlib/attribute/i_document_weight_attribute.h
index e0cfd446da5..e76fbcb0378 100644
--- a/searchlib/src/vespa/searchlib/attribute/i_document_weight_attribute.h
+++ b/searchlib/src/vespa/searchlib/attribute/i_document_weight_attribute.h
@@ -33,7 +33,7 @@ struct IDocumentWeightAttribute
virtual void collect_folded(vespalib::datastore::EntryRef enum_idx, vespalib::datastore::EntryRef dictionary_snapshot, const std::function<void(vespalib::datastore::EntryRef)>& callback) const = 0;
virtual void create(vespalib::datastore::EntryRef idx, std::vector<DocumentWeightIterator> &dst) const = 0;
virtual DocumentWeightIterator create(vespalib::datastore::EntryRef idx) const = 0;
- virtual ~IDocumentWeightAttribute() {}
+ virtual ~IDocumentWeightAttribute() = default;
};
}
diff --git a/searchlib/src/vespa/searchlib/diskindex/diskindex.cpp b/searchlib/src/vespa/searchlib/diskindex/diskindex.cpp
index ddcee50c219..0125a4d40b4 100644
--- a/searchlib/src/vespa/searchlib/diskindex/diskindex.cpp
+++ b/searchlib/src/vespa/searchlib/diskindex/diskindex.cpp
@@ -2,6 +2,8 @@
#include "diskindex.h"
#include "disktermblueprint.h"
+#include "pagedict4randread.h"
+#include "fileheader.h"
#include <vespa/searchlib/index/schemautil.h>
#include <vespa/searchlib/queryeval/create_blueprint_visitor_helper.h>
#include <vespa/searchlib/queryeval/leaf_blueprints.h>
@@ -10,8 +12,6 @@
#include <vespa/vespalib/stllike/hash_set.h>
#include <vespa/vespalib/stllike/hash_map.hpp>
#include <vespa/vespalib/stllike/cache.hpp>
-#include "pagedict4randread.h"
-#include "fileheader.h"
#include <vespa/log/log.h>
LOG_SETUP(".diskindex.diskindex");
diff --git a/searchlib/src/vespa/searchlib/parsequery/stackdumpiterator.cpp b/searchlib/src/vespa/searchlib/parsequery/stackdumpiterator.cpp
index 9b0196f4f29..d28c0cf1315 100644
--- a/searchlib/src/vespa/searchlib/parsequery/stackdumpiterator.cpp
+++ b/searchlib/src/vespa/searchlib/parsequery/stackdumpiterator.cpp
@@ -4,32 +4,33 @@
#include <vespa/vespalib/util/compress.h>
#include <vespa/vespalib/objects/nbo.h>
#include <cassert>
+#include <charconv>
using search::query::PredicateQueryTerm;
namespace search {
SimpleQueryStackDumpIterator::SimpleQueryStackDumpIterator(vespalib::stringref buf) :
- _buf(buf.begin()),
- _bufEnd(buf.end()),
- _bufLen(buf.size()),
- _currPos(_buf),
- _currEnd(_buf),
- _currType(ParseItem::ITEM_UNDEF),
- _currCreator(ParseItem::CREA_ORIG),
- _currWeight(100),
- _currUniqueId(0),
- _currFlags(0),
- _currArity(0),
- _extraIntArg1(0),
- _extraIntArg2(0),
- _extraIntArg3(0),
- _extraDoubleArg4(0),
- _extraDoubleArg5(0),
- _predicate_query_term(),
- _curr_index_name(),
- _curr_term(),
- _generatedTerm()
+ _buf(buf.begin()),
+ _bufEnd(buf.end()),
+ _bufLen(buf.size()),
+ _currPos(_buf),
+ _currEnd(_buf),
+ _currType(ParseItem::ITEM_UNDEF),
+ _currCreator(ParseItem::CREA_ORIG),
+ _currWeight(100),
+ _currUniqueId(0),
+ _currFlags(0),
+ _currArity(0),
+ _curr_index_name(),
+ _curr_term(),
+ _scratch(),
+ _extraIntArg1(0),
+ _extraIntArg2(0),
+ _extraIntArg3(0),
+ _extraDoubleArg4(0),
+ _extraDoubleArg5(0),
+ _predicate_query_term()
{
}
@@ -188,14 +189,15 @@ SimpleQueryStackDumpIterator::next()
}
break;
case ParseItem::ITEM_PURE_WEIGHTED_LONG:
- if (p + sizeof(int64_t) > _bufEnd) return false;
- _generatedTerm.clear();
- _generatedTerm << vespalib::nbo::n2h(*reinterpret_cast<const int64_t *>(p));
- _curr_term = vespalib::stringref(_generatedTerm.c_str(), _generatedTerm.size());
- p += sizeof(int64_t);
- if (p > _bufEnd) return false;
-
- _currArity = 0;
+ {
+ if (p + sizeof(int64_t) > _bufEnd) return false;
+ int64_t value = vespalib::nbo::n2h(*reinterpret_cast<const int64_t *>(p));
+ auto res = std::to_chars(_scratch, _scratch + sizeof(_scratch), value, 10);
+ _curr_term = vespalib::stringref(_scratch, res.ptr - _scratch);
+ p += sizeof(int64_t);
+ if (p > _bufEnd) return false;
+ _currArity = 0;
+ }
break;
case ParseItem::ITEM_WORD_ALTERNATIVES:
try {
@@ -239,8 +241,7 @@ SimpleQueryStackDumpIterator::next()
vespalib::string key = readString(p);
uint64_t value = readUint64(p);
uint64_t sub_queries = readUint64(p);
- _predicate_query_term->addRangeFeature(
- key, value, sub_queries);
+ _predicate_query_term->addRangeFeature(key, value, sub_queries);
}
if (p > _bufEnd) return false;
} catch (...) {
diff --git a/searchlib/src/vespa/searchlib/parsequery/stackdumpiterator.h b/searchlib/src/vespa/searchlib/parsequery/stackdumpiterator.h
index 301929c8919..287ed62d085 100644
--- a/searchlib/src/vespa/searchlib/parsequery/stackdumpiterator.h
+++ b/searchlib/src/vespa/searchlib/parsequery/stackdumpiterator.h
@@ -4,7 +4,6 @@
#include <vespa/searchlib/parsequery/parse.h>
#include <vespa/searchlib/query/tree/predicate_query_term.h>
-#include <vespa/vespalib/stllike/asciistream.h>
#include <vespa/vespalib/stllike/string.h>
namespace search {
@@ -15,9 +14,6 @@ namespace search {
class SimpleQueryStackDumpIterator
{
private:
- SimpleQueryStackDumpIterator(const SimpleQueryStackDumpIterator &);
- SimpleQueryStackDumpIterator& operator=(const SimpleQueryStackDumpIterator &);
-
/** Pointer to the start of the input buffer */
const char *_buf;
/** Pointer to just past the input buffer */
@@ -42,36 +38,33 @@ private:
/** The arity of the current item */
uint32_t _currArity;
+ /** The index name (field name) in the current item */
+ vespalib::stringref _curr_index_name;
+ /** The term in the current item */
+ vespalib::stringref _curr_term;
+ char _scratch[24];
/* extra arguments */
uint32_t _extraIntArg1;
uint32_t _extraIntArg2;
uint32_t _extraIntArg3;
- double _extraDoubleArg4;
- double _extraDoubleArg5;
+ double _extraDoubleArg4;
+ double _extraDoubleArg5;
/** The predicate query specification */
query::PredicateQueryTerm::UP _predicate_query_term;
- /** The index name (field name) in the current item */
- vespalib::stringref _curr_index_name;
- /** The term in the current item */
- vespalib::stringref _curr_term;
- vespalib::asciistream _generatedTerm;
-
- vespalib::string readString(const char *&p);
- vespalib::stringref read_stringref(const char *&p);
- uint64_t readUint64(const char *&p);
- double read_double(const char *&p);
- uint64_t readCompressedPositiveInt(const char *&p);
+ VESPA_DLL_LOCAL vespalib::string readString(const char *&p);
+ VESPA_DLL_LOCAL vespalib::stringref read_stringref(const char *&p);
+ VESPA_DLL_LOCAL uint64_t readUint64(const char *&p);
+ VESPA_DLL_LOCAL double read_double(const char *&p);
+ VESPA_DLL_LOCAL uint64_t readCompressedPositiveInt(const char *&p);
public:
/**
- * Make an iterator on a buffer. To get the first item, next
- * must be called.
- *
- * @param buf A pointer to the buffer holding the stackdump
- * @param buflen The length of the buffer in bytes
+ * Make an iterator on a buffer. To get the first item, next must be called.
*/
SimpleQueryStackDumpIterator(vespalib::stringref buf);
+ SimpleQueryStackDumpIterator(const SimpleQueryStackDumpIterator &) = delete;
+ SimpleQueryStackDumpIterator& operator=(const SimpleQueryStackDumpIterator &) = delete;
~SimpleQueryStackDumpIterator();
vespalib::stringref getStack() const { return vespalib::stringref(_buf, _bufLen); }
@@ -125,12 +118,10 @@ public:
bool getAllowApproximate() const { return (_extraIntArg2 != 0); }
uint32_t getExploreAdditionalHits() const { return _extraIntArg3; }
- query::PredicateQueryTerm::UP getPredicateQueryTerm()
- { return std::move(_predicate_query_term); }
+ query::PredicateQueryTerm::UP getPredicateQueryTerm() { return std::move(_predicate_query_term); }
vespalib::stringref getIndexName() const { return _curr_index_name; }
vespalib::stringref getTerm() const { return _curr_term; }
};
}
-
diff --git a/searchlib/src/vespa/searchlib/query/tree/stackdumpquerycreator.h b/searchlib/src/vespa/searchlib/query/tree/stackdumpquerycreator.h
index 040ac751d25..eab397d321c 100644
--- a/searchlib/src/vespa/searchlib/query/tree/stackdumpquerycreator.h
+++ b/searchlib/src/vespa/searchlib/query/tree/stackdumpquerycreator.h
@@ -50,7 +50,7 @@ private:
uint32_t arity = queryStack.getArity();
ParseItem::ItemType type = queryStack.getType();
Node::UP node;
- Term *t = 0;
+ Term *t = nullptr;
if (type == ParseItem::ITEM_AND) {
builder.addAnd(arity);
} else if (type == ParseItem::ITEM_RANK) {