summaryrefslogtreecommitdiffstats
path: root/src/kv/LevelDBStore.cc
diff options
context:
space:
mode:
authorSage Weil <sage@redhat.com>2015-10-19 20:06:17 +0200
committerSage Weil <sage@redhat.com>2015-10-19 20:06:28 +0200
commitca72d506cd73e5665a77e6113c83927f879d18ad (patch)
tree2a9bd83a9e2b7935b8b06707c8321ca2750ab943 /src/kv/LevelDBStore.cc
parentkv/RocksDBStore: make get() avoid bufferlist copy most of the time (diff)
downloadceph-ca72d506cd73e5665a77e6113c83927f879d18ad.tar.xz
ceph-ca72d506cd73e5665a77e6113c83927f879d18ad.zip
kv/LevelDBStore: make set() avoid bufferlist copy most of the time
Signed-off-by: Sage Weil <sage@redhat.com>
Diffstat (limited to 'src/kv/LevelDBStore.cc')
-rw-r--r--src/kv/LevelDBStore.cc16
1 files changed, 12 insertions, 4 deletions
diff --git a/src/kv/LevelDBStore.cc b/src/kv/LevelDBStore.cc
index 92c915810f6..a46558a5ca2 100644
--- a/src/kv/LevelDBStore.cc
+++ b/src/kv/LevelDBStore.cc
@@ -164,11 +164,19 @@ void LevelDBStore::LevelDBTransactionImpl::set(
const bufferlist &to_set_bl)
{
string key = combine_strings(prefix, k);
- //bufferlist::c_str() is non-constant, so we need to make a copy
- bufferlist val = to_set_bl;
bat.Delete(leveldb::Slice(key));
- bat.Put(leveldb::Slice(key),
- leveldb::Slice(val.c_str(), val.length()));
+
+ // bufferlist::c_str() is non-constant, so we can't call c_str()
+ if (to_set_bl.is_contiguous() && to_set_bl.length() > 0) {
+ bat.Put(leveldb::Slice(key),
+ leveldb::Slice(to_set_bl.buffers().front().c_str(),
+ to_set_bl.length()));
+ } else {
+ // make a copy
+ bufferlist val = to_set_bl;
+ bat.Put(leveldb::Slice(key),
+ leveldb::Slice(val.c_str(), val.length()));
+ }
}
void LevelDBStore::LevelDBTransactionImpl::rmkey(const string &prefix,