summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorHenning Baldersheim <balder@oath.com>2018-11-02 15:09:28 +0100
committerHenning Baldersheim <balder@oath.com>2018-11-02 15:09:28 +0100
commit3a10bfc113278a206fd61ea8ff1e2b1afb04aa16 (patch)
treef5b1bb56266bbf819130005ec02a1996fa771b39
parent2740969f948dcf1e27d1a23dd1e45afadbf9857e (diff)
Remove reduandant cast and type specification along with some unused code.
-rw-r--r--searchlib/src/vespa/searchlib/aggregation/group.cpp70
-rw-r--r--searchlib/src/vespa/searchlib/aggregation/group.h18
-rw-r--r--searchlib/src/vespa/searchlib/fef/properties.cpp2
-rw-r--r--staging_vespalib/src/vespa/vespalib/objects/identifiable.cpp32
4 files changed, 44 insertions, 78 deletions
diff --git a/searchlib/src/vespa/searchlib/aggregation/group.cpp b/searchlib/src/vespa/searchlib/aggregation/group.cpp
index ca22707ec27..17e56c9af21 100644
--- a/searchlib/src/vespa/searchlib/aggregation/group.cpp
+++ b/searchlib/src/vespa/searchlib/aggregation/group.cpp
@@ -34,8 +34,8 @@ struct SortByGroupRank {
}
};
-void reset(Group * & v) { v = NULL; }
-void destruct(Group * v) { if (v) { delete v; } }
+void reset(Group * & v) { v = nullptr; }
+void destruct(Group * v) { delete v; }
void
destruct(Group::GroupList & l, size_t m)
@@ -44,7 +44,7 @@ destruct(Group::GroupList & l, size_t m)
destruct(l[i]);
}
delete [] l;
- l = NULL;
+ l = nullptr;
}
}
@@ -97,13 +97,13 @@ Group::groupNext(const GroupingLevel & level, const Doc & doc, HitRank rank)
Group *
Group::Value::groupSingle(const ResultNode & selectResult, HitRank rank, const GroupingLevel & level)
{
- if (_childInfo._childMap == NULL) {
+ if (_childInfo._childMap == nullptr) {
assert(getChildrenSize() == 0);
_childInfo._childMap = new GroupHash(1, GroupHasher(&_children), GroupEqual(&_children));
}
GroupHash & childMap = *_childInfo._childMap;
- Group * group(NULL);
- GroupHash::iterator found = childMap.find<ResultNode>(selectResult);
+ Group * group(nullptr);
+ GroupHash::iterator found = childMap.find(selectResult);
if (found == childMap.end()) { // group not present in child map
if (level.allowMoreGroups(childMap.size())) {
group = new Group(level.getGroupPrototype());
@@ -203,7 +203,7 @@ Group::Group() :
Group::Group(const Group & rhs) = default;
Group & Group::operator = (const Group & rhs) = default;
-Group::~Group() { }
+Group::~Group() = default;
Group &
Group::partialCopy(const Group & rhs) {
@@ -230,7 +230,7 @@ void
Group::Value::addExpressionResult(ExpressionNode::UP expressionNode)
{
uint32_t newSize = getAggrSize() + getExprSize() + 1;
- ExpressionVector n = new ExpressionNode::CP[newSize];
+ auto n = new ExpressionNode::CP[newSize];
for (uint32_t i(0); i < (newSize - 1); i++) {
n[i] = std::move(_aggregationResults[i]);
}
@@ -246,7 +246,7 @@ Group::Value::addAggregationResult(ExpressionNode::UP aggr)
{
assert(getAggrSize() < 15);
size_t newSize = getAggrSize() + 1 + getExprSize();
- ExpressionVector n = new ExpressionNode::CP[newSize];
+ auto n = new ExpressionNode::CP[newSize];
for (size_t i(0), m(getAggrSize()); i < m; i++) {
n[i] = std::move(_aggregationResults[i]);
}
@@ -292,10 +292,10 @@ Group::Value::addChild(Group * child)
{
const size_t sz(getChildrenSize());
assert(sz < 0xffffff);
- if (_children == 0) {
+ if (_children == nullptr) {
_children = new ChildP[4];
} else if ((sz >=4) && vespalib::Optimized::msbIdx(sz) == vespalib::Optimized::lsbIdx(sz)) {
- GroupList n = new ChildP[sz*2];
+ auto n = new ChildP[sz*2];
for (size_t i(0), m(getChildrenSize()); i < m; i++) {
n[i] = _children[i];
}
@@ -317,7 +317,7 @@ Group::Value::select(const vespalib::ObjectPredicate &predicate, vespalib::Objec
void
Group::Value::preAggregate()
{
- assert(_childInfo._childMap == NULL);
+ assert(_childInfo._childMap == nullptr);
_childInfo._childMap = new GroupHash(getChildrenSize()*2, GroupHasher(&_children), GroupEqual(&_children));
GroupHash & childMap = *_childInfo._childMap;
for (ChildP *it(_children), *mt(_children + getChildrenSize()); it != mt; ++it) {
@@ -330,7 +330,7 @@ void
Group::Value::postAggregate()
{
delete _childInfo._childMap;
- _childInfo._childMap = NULL;
+ _childInfo._childMap = nullptr;
for (ChildP *it(_children), *mt(_children + getChildrenSize()); it != mt; ++it) {
(*it)->postAggregate();
}
@@ -372,7 +372,7 @@ Group::Value::execute() {
void
Group::Value::mergeLevel(const Group & protoType, const Value & b) {
for (ChildP *it(b._children), *mt(b._children + b.getChildrenSize()); it != mt; ++it) {
- ChildP g(new Group(protoType));
+ auto g(new Group(protoType));
g->partialCopy(**it);
addChild(g);
}
@@ -382,7 +382,7 @@ void
Group::Value::merge(const std::vector<GroupingLevel> &levels,
uint32_t firstLevel, uint32_t currentLevel, const Value &b)
{
- GroupList z = new ChildP[getChildrenSize() + b.getChildrenSize()];
+ auto z = new ChildP[getChildrenSize() + b.getChildrenSize()];
size_t kept(0);
ChildP * px = _children;
ChildP * ex = _children + getChildrenSize();
@@ -422,7 +422,7 @@ Group::Value::merge(const std::vector<GroupingLevel> &levels,
void
Group::Value::prune(const Value & b, uint32_t lastLevel, uint32_t currentLevel) {
- GroupList keep = new ChildP[b.getChildrenSize()];
+ auto keep = new ChildP[b.getChildrenSize()];
size_t kept(0);
ChildP * px = _children;
ChildP * ex = _children + getAllChildrenSize();
@@ -562,7 +562,7 @@ Group::Value::deserialize(Deserializer & is) {
// results into a temporary buffer, and then reallocate the actual
// vector when we know the total size. Then we copy the temp buffer and
// deserialize the rest to the end of the vector.
- ExpressionVector tmpAggregationResults = new ExpressionNode::CP[aggrSize];
+ auto tmpAggregationResults = new ExpressionNode::CP[aggrSize];
setAggrSize(aggrSize);
for(uint32_t i(0); i < aggrSize; i++) {
is >> tmpAggregationResults[i];
@@ -589,7 +589,7 @@ Group::Value::deserialize(Deserializer & is) {
_children = new ChildP[std::max(4ul, 2ul << vespalib::Optimized::msbIdx(count))];
setChildrenSize(count);
for(uint32_t i(0); i < count; i++) {
- ChildP group(new Group);
+ auto group(new Group);
is >> *group;
_children[i] = group;
}
@@ -633,24 +633,24 @@ Group::Value::visitMembers(vespalib::ObjectVisitor &visitor) const {
Group::Value::Value() :
_packedLength(0),
_tag(-1),
- _aggregationResults(NULL),
- _children(NULL),
+ _aggregationResults(nullptr),
+ _children(nullptr),
_childInfo(),
_orderBy()
{
memset(_orderBy, 0, sizeof(_orderBy));
- _childInfo._childMap = NULL;
+ _childInfo._childMap = nullptr;
}
Group::Value::Value(const Value & rhs) :
_packedLength(rhs._packedLength),
_tag(rhs._tag),
- _aggregationResults(NULL),
- _children(NULL),
+ _aggregationResults(nullptr),
+ _children(nullptr),
_childInfo(),
_orderBy()
{
- _childInfo._childMap = NULL;
+ _childInfo._childMap = nullptr;
memcpy(_orderBy, rhs._orderBy, sizeof(_orderBy));
uint32_t totalAggrSize = rhs.getAggrSize() + rhs.getExprSize();
if (totalAggrSize > 0) {
@@ -665,17 +665,17 @@ Group::Value::Value(const Value & rhs) :
_children = new ChildP[std::max(4ul, 2ul << vespalib::Optimized::msbIdx(rhs.getChildrenSize()))];
size_t i(0);
for (const ChildP *it(rhs._children), *mt(rhs._children + rhs.getChildrenSize()); it != mt; ++it, i++) {
- _children[i] = ChildP(new Group(**it));
+ _children[i] = new Group(**it);
}
}
}
Group::Value::Value(Value && rhs) noexcept :
- _packedLength(std::move(rhs._packedLength)),
- _tag(std::move(rhs._tag)),
- _aggregationResults(std::move(rhs._aggregationResults)),
- _children(std::move(rhs._children)),
- _childInfo(std::move(rhs._childInfo)),
+ _packedLength(rhs._packedLength),
+ _tag(rhs._tag),
+ _aggregationResults(rhs._aggregationResults),
+ _children(rhs._children),
+ _childInfo(rhs._childInfo),
_orderBy()
{
memcpy(_orderBy, rhs._orderBy, sizeof(_orderBy));
@@ -688,11 +688,11 @@ Group::Value::Value(Value && rhs) noexcept :
Group::Value &
Group::Value::operator =(Value && rhs) noexcept {
- _packedLength = std::move(rhs._packedLength);
- _tag = std::move(rhs._tag);
- _aggregationResults = std::move(rhs._aggregationResults);
- _children = std::move(rhs._children);
- _childInfo = std::move(rhs._childInfo);
+ _packedLength = rhs._packedLength;
+ _tag = rhs._tag;
+ _aggregationResults = rhs._aggregationResults;
+ _children = rhs._children;
+ _childInfo = rhs._childInfo;
memcpy(_orderBy, rhs._orderBy, sizeof(_orderBy));
rhs.setChildrenSize(0);
diff --git a/searchlib/src/vespa/searchlib/aggregation/group.h b/searchlib/src/vespa/searchlib/aggregation/group.h
index fe3f19cb615..f302346f211 100644
--- a/searchlib/src/vespa/searchlib/aggregation/group.h
+++ b/searchlib/src/vespa/searchlib/aggregation/group.h
@@ -55,20 +55,6 @@ public:
size_t operator() (const ResultNode & arg) const { return arg.hash(); }
const GroupList *_v;
};
- struct GroupResult {
- GroupResult(const GroupList * v) : _v(v) { }
- const ResultNode & operator() (uint32_t arg) const { return (*_v)[arg]->getId(); }
- const GroupList *_v;
- };
- struct ResultLess : public std::binary_function<ResultNode::CP, ResultNode::CP, bool> {
- bool operator()(const ResultNode::CP & a, const ResultNode::CP & b) { return a->cmpFast(*b) < 0; }
- };
- struct ResultEqual : public std::binary_function<ResultNode, ResultNode, bool> {
- bool operator()(const ResultNode & a, const ResultNode & b) { return a.cmpFast(b) == 0; }
- };
- struct ResultHash {
- size_t operator() (const ResultNode & arg) const { return arg.hash(); }
- };
using GroupingLevelList = std::vector<GroupingLevel>;
@@ -198,12 +184,12 @@ public:
return _aggr.groupSingle(result, rank, level);
}
- bool hasId() const { return (_id.get() != NULL); }
+ bool hasId() const { return static_cast<bool>(_id); }
const ResultNode &getId() const { return *_id; }
Group unchain() const { return *this; }
- Group &setId(const ResultNode &id) { _id.reset(static_cast<ResultNode *>(id.clone())); return *this; }
+ Group &setId(const ResultNode &id) { _id.reset(id.clone()); return *this; }
Group &addAggregationResult(ExpressionNode::UP result) {
_aggr.addAggregationResult(std::move(result));
return *this;
diff --git a/searchlib/src/vespa/searchlib/fef/properties.cpp b/searchlib/src/vespa/searchlib/fef/properties.cpp
index dc4dcce8865..95b74cd5dfd 100644
--- a/searchlib/src/vespa/searchlib/fef/properties.cpp
+++ b/searchlib/src/vespa/searchlib/fef/properties.cpp
@@ -209,7 +209,7 @@ Properties::lookup(vespalib::stringref key) const
if (key.empty()) {
return Property();
}
- Map::const_iterator node = _data.find<vespalib::stringref>(key);
+ Map::const_iterator node = _data.find(key);
if (node == _data.end()) {
return Property();
}
diff --git a/staging_vespalib/src/vespa/vespalib/objects/identifiable.cpp b/staging_vespalib/src/vespa/vespalib/objects/identifiable.cpp
index ecd7aed185b..84bdc0a45d0 100644
--- a/staging_vespalib/src/vespa/vespalib/objects/identifiable.cpp
+++ b/staging_vespalib/src/vespa/vespalib/objects/identifiable.cpp
@@ -27,8 +27,6 @@ public:
bool erase(RuntimeClass * c);
const RuntimeClass * classFromId(unsigned id) const;
const RuntimeClass * classFromName(const char * name) const;
- const char * id2Name(unsigned id) const;
- unsigned name2Id(const char * name) const;
bool empty() const { return _listById.empty(); }
private:
struct HashId {
@@ -39,19 +37,15 @@ private:
bool operator() (const RuntimeClass * a, const RuntimeClass * b) const { return a->id() == b->id(); }
bool operator() (const RuntimeClass * a, uint32_t b) const { return a->id() == b; }
bool operator() (uint32_t a, const RuntimeClass * b) const { return a == b->id(); }
-
-
};
struct HashName {
uint32_t operator() (const RuntimeClass * f) const { return hashValue(f->name()); }
uint32_t operator() (const char * name) const { return hashValue(name); }
-
};
struct EqualName {
bool operator() (const RuntimeClass * a, const RuntimeClass * b) const { return strcmp(a->name(), b->name()) == 0; }
bool operator() (const RuntimeClass * a, const char * b) const { return strcmp(a->name(), b) == 0; }
bool operator() (const char * a, const RuntimeClass * b) const { return strcmp(a, b->name()) == 0; }
-
};
using IdList = hash_set<RuntimeClass *, HashId, EqualId>;
using NameList = hash_set<RuntimeClass *, HashName, EqualName>;
@@ -131,7 +125,7 @@ Identifiable::RuntimeClass::RuntimeClass(RuntimeInfo * info_) :
}
}
}
- if (_register == NULL) {
+ if (_register == nullptr) {
_register = new Register();
}
if (! _register->append(this)) {
@@ -147,7 +141,7 @@ Identifiable::RuntimeClass::~RuntimeClass()
}
if (_register->empty()) {
delete _register;
- _register = NULL;
+ _register = nullptr;
}
}
@@ -158,20 +152,6 @@ bool Identifiable::RuntimeClass::inherits(unsigned cid) const
return (cid == cur->_id);
}
-class SortById : public std::binary_function<const Identifiable::RuntimeClass *, const Identifiable::RuntimeClass *, bool> {
-public:
- bool operator() (const Identifiable::RuntimeClass * x, const Identifiable::RuntimeClass * y) const {
- return x->id() < y->id();
- }
-};
-
-class SortByName : public std::binary_function<const Identifiable::RuntimeClass *, const Identifiable::RuntimeClass *, bool> {
-public:
- bool operator() (const Identifiable::RuntimeClass * x, const Identifiable::RuntimeClass * y) const {
- return strcmp(x->name(), y->name()) < 0;
- }
-};
-
Serializer & operator << (Serializer & os, const Identifiable & obj)
{
os.put(Identifiable::classIdField, obj.getClass().id());
@@ -215,16 +195,16 @@ Identifiable::UP Identifiable::create(Deserializer & is)
is.get(classIdField, cid);
UP obj;
const Identifiable::RuntimeClass *rtc = Identifiable::classFromId(cid);
- if (rtc == NULL) {
- if ((_classLoader != NULL) && _classLoader->hasClass(cid)) {
+ if (rtc == nullptr) {
+ if ((_classLoader != nullptr) && _classLoader->hasClass(cid)) {
_classLoader->loadClass(cid);
rtc = Identifiable::classFromId(cid);
- if (rtc == NULL) {
+ if (rtc == nullptr) {
throw std::runtime_error(make_string("Failed loading class for Identifiable with classId %d(%0x)", cid, cid));
}
}
}
- if (rtc != NULL) {
+ if (rtc != nullptr) {
obj.reset(rtc->create());
if (obj.get()) {
obj->deserialize(is);