aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGeir Storli <geirst@verizonmedia.com>2019-05-07 10:54:30 +0000
committerGeir Storli <geirst@verizonmedia.com>2019-05-07 10:54:30 +0000
commitc6eaba56a56506e3df6cdb5ab15bfbfcca320ece (patch)
tree4727755eab3c10e06dd8c0d48236c5129e3cf465
parentf6abfa69311f21b5184590ce963760ab345f5b5e (diff)
Avoid raw pointers in FakeWordSet.
-rw-r--r--searchlib/src/tests/postinglistbm/andstress.cpp2
-rw-r--r--searchlib/src/vespa/searchlib/test/fakedata/fakewordset.cpp71
-rw-r--r--searchlib/src/vespa/searchlib/test/fakedata/fakewordset.h8
-rw-r--r--searchlib/src/vespa/searchlib/test/fakedata/fpfactory.cpp9
4 files changed, 34 insertions, 56 deletions
diff --git a/searchlib/src/tests/postinglistbm/andstress.cpp b/searchlib/src/tests/postinglistbm/andstress.cpp
index 7152e2a3981..fc5141e23d0 100644
--- a/searchlib/src/tests/postinglistbm/andstress.cpp
+++ b/searchlib/src/tests/postinglistbm/andstress.cpp
@@ -194,7 +194,7 @@ AndStressMaster::resetTasks()
static void
makeSomePostings(FPFactory *postingFactory,
- std::vector<FakeWord *> &words,
+ FakeWordSet::FakeWordVector &words,
std::vector<FakePosting::SP> &postings,
uint32_t stride,
bool validate,
diff --git a/searchlib/src/vespa/searchlib/test/fakedata/fakewordset.cpp b/searchlib/src/vespa/searchlib/test/fakedata/fakewordset.cpp
index a09e75bc132..5c87bf88e9c 100644
--- a/searchlib/src/vespa/searchlib/test/fakedata/fakewordset.cpp
+++ b/searchlib/src/vespa/searchlib/test/fakedata/fakewordset.cpp
@@ -10,28 +10,23 @@ LOG_SETUP(".fakewordset");
namespace search::fakedata {
+using FakeWordVector = FakeWordSet::FakeWordVector;
using index::PostingListParams;
using index::SchemaUtil;
using index::schema::CollectionType;
using index::schema::DataType;
-void
-clearFakeWordVector(std::vector<FakeWord *> &v)
-{
- for (unsigned int i = 0; i < v.size(); ++i) {
- delete v[i];
- }
- v.clear();
-}
+namespace {
void
-applyDocIdBiasToVector(std::vector<FakeWord *> &v, uint32_t docIdBias)
+applyDocIdBiasToVector(FakeWordVector& words, uint32_t docIdBias)
{
- for (unsigned int i = 0; i < v.size(); ++i) {
- v[i]->addDocIdBias(docIdBias);
+ for (auto& word : words) {
+ word->addDocIdBias(docIdBias);
}
}
+}
FakeWordSet::FakeWordSet()
: _words(NUM_WORDCLASSES),
@@ -50,10 +45,7 @@ FakeWordSet::FakeWordSet(bool hasElements,
setupParams(hasElements, hasElementWeights);
}
-FakeWordSet::~FakeWordSet()
-{
- dropWords();
-}
+FakeWordSet::~FakeWordSet() = default;
void
FakeWordSet::setupParams(bool hasElements,
@@ -90,7 +82,6 @@ FakeWordSet::setupWords(search::Rand48 &rnd,
std::string common = "common";
std::string medium = "medium";
std::string rare = "rare";
- FakeWord *fw;
FastOS_Time tv;
double before;
double after;
@@ -103,42 +94,32 @@ FakeWordSet::setupWords(search::Rand48 &rnd,
std::ostringstream vi;
vi << (i + 1);
- fw = new FakeWord(numDocs, commonDocFreq, commonDocFreq / 2,
- common + vi.str(), rnd,
- _fieldsParams[packedIndex],
- packedIndex);
- _words[COMMON_WORD].push_back(fw);
- fw = new FakeWord(numDocs, 1000, 500,
- medium + vi.str(), rnd,
- _fieldsParams[packedIndex],
- packedIndex);
- _words[MEDIUM_WORD].push_back(fw);
- fw = new FakeWord(numDocs, 10, 5,
- rare + vi.str(), rnd,
- _fieldsParams[packedIndex],
- packedIndex);
- _words[RARE_WORD].push_back(fw);
+ _words[COMMON_WORD].push_back(std::make_unique<FakeWord>(numDocs, commonDocFreq, commonDocFreq / 2,
+ common + vi.str(), rnd,
+ _fieldsParams[packedIndex],
+ packedIndex));
+
+ _words[MEDIUM_WORD].push_back(std::make_unique<FakeWord>(numDocs, 1000, 500,
+ medium + vi.str(), rnd,
+ _fieldsParams[packedIndex],
+ packedIndex));
+
+ _words[RARE_WORD].push_back(std::make_unique<FakeWord>(numDocs, 10, 5,
+ rare + vi.str(), rnd,
+ _fieldsParams[packedIndex],
+ packedIndex));
}
tv.SetNow();
after = tv.Secs();
LOG(info, "leave setupWords, elapsed %10.6f s", after - before);
}
-void
-FakeWordSet::dropWords()
-{
- for (unsigned int i = 0; i < _words.size(); ++i) {
- clearFakeWordVector(_words[i]);
- }
-}
-
-
int
-FakeWordSet::getNumWords()
+FakeWordSet::getNumWords() const
{
int ret = 0;
- for (unsigned int i = 0; i < _words.size(); ++i) {
- ret += _words[i].size();
+ for (const auto& words : _words) {
+ ret += words.size();
}
return ret;
}
@@ -146,8 +127,8 @@ FakeWordSet::getNumWords()
void
FakeWordSet::addDocIdBias(uint32_t docIdBias)
{
- for (unsigned int i = 0; i < _words.size(); ++i) {
- applyDocIdBiasToVector(_words[i], docIdBias);
+ for (auto& words : _words) {
+ applyDocIdBiasToVector(words, docIdBias);
}
}
diff --git a/searchlib/src/vespa/searchlib/test/fakedata/fakewordset.h b/searchlib/src/vespa/searchlib/test/fakedata/fakewordset.h
index 325b929ce6f..146bef5c9ec 100644
--- a/searchlib/src/vespa/searchlib/test/fakedata/fakewordset.h
+++ b/searchlib/src/vespa/searchlib/test/fakedata/fakewordset.h
@@ -18,6 +18,8 @@ class FakeWordSet {
public:
using PosOccFieldsParams = bitcompression::PosOccFieldsParams;
using Schema = index::Schema;
+ using FakeWordPtr = std::unique_ptr<FakeWord>;
+ using FakeWordVector = std::vector<FakeWordPtr>;
enum {
COMMON_WORD,
@@ -25,7 +27,7 @@ public:
RARE_WORD,
NUM_WORDCLASSES,
};
- std::vector<std::vector<FakeWord *> > _words;
+ std::vector<FakeWordVector> _words;
Schema _schema;
std::vector<PosOccFieldsParams> _fieldsParams;
@@ -44,9 +46,7 @@ public:
unsigned int commonDocFreq,
unsigned int numWordsPerWordClass);
- void dropWords();
-
- int getNumWords();
+ int getNumWords() const;
const PosOccFieldsParams& getFieldsParams() const {
return _fieldsParams.back();
diff --git a/searchlib/src/vespa/searchlib/test/fakedata/fpfactory.cpp b/searchlib/src/vespa/searchlib/test/fakedata/fpfactory.cpp
index f10af286dd7..790db2dd0b2 100644
--- a/searchlib/src/vespa/searchlib/test/fakedata/fpfactory.cpp
+++ b/searchlib/src/vespa/searchlib/test/fakedata/fpfactory.cpp
@@ -19,12 +19,9 @@ FPFactory::setup(const FakeWordSet &fws)
{
std::vector<const FakeWord *> v;
- for (uint32_t wc = 0; wc < fws._words.size(); ++wc) {
- std::vector<FakeWord *>::const_iterator fwi(fws._words[wc].begin());
- std::vector<FakeWord *>::const_iterator fwe(fws._words[wc].end());
- while (fwi != fwe) {
- v.push_back(*fwi);
- ++fwi;
+ for (const auto& words : fws._words) {
+ for (const auto& word : words) {
+ v.push_back(word.get());
}
}
setup(v);