mirror of
https://github.com/ceph/ceph
synced 2025-04-01 00:26:47 +00:00
os/KeyValueDB: don't call self.valid() from next() and prev()
In most loops using ObjectMapIteratorImpl, there is a call to valid() followed by a call to next(), which calls valid() again. Calling valid() alone is particularly expensive, so don't do it twice if possible. Signed-off-by: Piotr Dałek <piotr.dalek@ts.fujitsu.com>
This commit is contained in:
parent
66b7b920cf
commit
117f40c690
@ -141,7 +141,7 @@ public:
|
||||
virtual int upper_bound(const std::string &after) = 0;
|
||||
virtual int lower_bound(const std::string &to) = 0;
|
||||
virtual bool valid() = 0;
|
||||
virtual int next() = 0;
|
||||
virtual int next(bool validate=true) = 0;
|
||||
virtual std::string key() = 0;
|
||||
virtual bufferlist value() = 0;
|
||||
virtual int status() = 0;
|
||||
@ -193,15 +193,26 @@ public:
|
||||
return false;
|
||||
return generic_iter->raw_key_is_prefixed(prefix);
|
||||
}
|
||||
int next() {
|
||||
if (valid())
|
||||
return generic_iter->next();
|
||||
return status();
|
||||
// Note that next() and prev() shouldn't validate iters,
|
||||
// it's responsibility of caller to ensure they're valid.
|
||||
int next(bool validate=true) {
|
||||
if (validate) {
|
||||
if (valid())
|
||||
return generic_iter->next();
|
||||
return status();
|
||||
} else {
|
||||
return generic_iter->next();
|
||||
}
|
||||
}
|
||||
int prev() {
|
||||
if (valid())
|
||||
return generic_iter->prev();
|
||||
return status();
|
||||
|
||||
int prev(bool validate=true) {
|
||||
if (validate) {
|
||||
if (valid())
|
||||
return generic_iter->prev();
|
||||
return status();
|
||||
} else {
|
||||
return generic_iter->prev();
|
||||
}
|
||||
}
|
||||
std::string key() {
|
||||
return generic_iter->key();
|
||||
|
@ -344,7 +344,7 @@ bool DBObjectMap::DBObjectMapIteratorImpl::valid_parent()
|
||||
return false;
|
||||
}
|
||||
|
||||
int DBObjectMap::DBObjectMapIteratorImpl::next()
|
||||
int DBObjectMap::DBObjectMapIteratorImpl::next(bool validate)
|
||||
{
|
||||
assert(cur_iter->valid());
|
||||
assert(valid());
|
||||
|
@ -347,7 +347,7 @@ private:
|
||||
int upper_bound(const string &after) { return 0; }
|
||||
int lower_bound(const string &to) { return 0; }
|
||||
bool valid() { return false; }
|
||||
int next() { assert(0); return 0; }
|
||||
int next(bool validate=true) { assert(0); return 0; }
|
||||
string key() { assert(0); return ""; }
|
||||
bufferlist value() { assert(0); return bufferlist(); }
|
||||
int status() { return 0; }
|
||||
@ -385,7 +385,7 @@ private:
|
||||
int upper_bound(const string &after);
|
||||
int lower_bound(const string &to);
|
||||
bool valid();
|
||||
int next();
|
||||
int next(bool validate=true);
|
||||
string key();
|
||||
bufferlist value();
|
||||
int status();
|
||||
|
@ -415,7 +415,7 @@ bool GenericObjectMap::GenericObjectMapIteratorImpl::valid_parent()
|
||||
return false;
|
||||
}
|
||||
|
||||
int GenericObjectMap::GenericObjectMapIteratorImpl::next()
|
||||
int GenericObjectMap::GenericObjectMapIteratorImpl::next(bool validate)
|
||||
{
|
||||
assert(cur_iter->valid());
|
||||
assert(valid());
|
||||
|
@ -298,7 +298,7 @@ private:
|
||||
int upper_bound(const string &after) { return 0; }
|
||||
int lower_bound(const string &to) { return 0; }
|
||||
bool valid() { return false; }
|
||||
int next() { assert(0); return 0; }
|
||||
int next(bool validate=true) { assert(0); return 0; }
|
||||
string key() { assert(0); return ""; }
|
||||
bufferlist value() { assert(0); return bufferlist(); }
|
||||
int status() { return 0; }
|
||||
@ -337,7 +337,7 @@ private:
|
||||
int upper_bound(const string &after);
|
||||
int lower_bound(const string &to);
|
||||
bool valid();
|
||||
int next();
|
||||
int next(bool validate=true);
|
||||
string key();
|
||||
bufferlist value();
|
||||
int status();
|
||||
|
@ -271,7 +271,7 @@ private:
|
||||
std::lock_guard<std::mutex>(o->omap_mutex);
|
||||
return it != o->omap.end();
|
||||
}
|
||||
int next() {
|
||||
int next(bool validate=true) {
|
||||
std::lock_guard<std::mutex>(o->omap_mutex);
|
||||
++it;
|
||||
return 0;
|
||||
|
@ -1708,7 +1708,7 @@ bool NewStore::OmapIteratorImpl::valid()
|
||||
}
|
||||
}
|
||||
|
||||
int NewStore::OmapIteratorImpl::next()
|
||||
int NewStore::OmapIteratorImpl::next(bool validate)
|
||||
{
|
||||
RWLock::RLocker l(c->lock);
|
||||
if (o->onode.omap_head) {
|
||||
|
@ -124,7 +124,7 @@ public:
|
||||
int upper_bound(const string &after);
|
||||
int lower_bound(const string &to);
|
||||
bool valid();
|
||||
int next();
|
||||
int next(bool validate=true);
|
||||
string key();
|
||||
bufferlist value();
|
||||
int status() {
|
||||
|
Loading…
Reference in New Issue
Block a user