Commit d637e054 authored by Matthieu Dorier's avatar Matthieu Dorier
Browse files

improved load() function by assuming a size for the object

parent b1e7da34
......@@ -189,23 +189,14 @@ class DataStore::Impl {
// make corresponding datastore entry
auto& db = m_databases[sdskv_db_idx];
// read the value
// find the size of the value, as a way to check if the key exists
// XXX optimization: instead of getting the size, we could try getting
// the data with a certain size and retry with the right size if it doesn't work
hg_size_t vsize;
if(data.size() == 0)
data.resize(2048); // eagerly allocate 2KB
try {
vsize = db.length(key);
db.get(key, data);
} catch(sdskv::exception& ex) {
if(ex.error() == SDSKV_ERR_UNKNOWN_KEY)
return false;
throw Exception("Error occured when calling sdskv::database::length");
try {
db.get(key, data);
} catch(sdskv::exception& ex) {
throw Exception("Error occured when calling sdskv::database::get");
return true;
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment