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,24 +189,15 @@ class DataStore::Impl { ...@@ -189,24 +189,15 @@ class DataStore::Impl {
// make corresponding datastore entry // make corresponding datastore entry
auto& db = m_databases[sdskv_db_idx]; auto& db = m_databases[sdskv_db_idx];
// read the value // read the value
// find the size of the value, as a way to check if the key exists if(data.size() == 0)
// XXX optimization: instead of getting the size, we could try getting data.resize(2048); // eagerly allocate 2KB
// the data with a certain size and retry with the right size if it doesn't work
hg_size_t vsize;
try { try {
vsize = db.length(key); db.get(key, data);
} catch(sdskv::exception& ex) { } catch(sdskv::exception& ex) {
if(ex.error() == SDSKV_ERR_UNKNOWN_KEY) if(ex.error() == SDSKV_ERR_UNKNOWN_KEY)
return false; return false;
else else
throw Exception("Error occured when calling sdskv::database::length"); throw Exception("Error occured when calling sdskv::database::get");
}
data.resize(vsize);
try {
db.get(key, data);
} catch(sdskv::exception& ex) {
throw Exception("Error occured when calling sdskv::database::get");
} }
return true; 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