Optimize multi_get_cf_opt() to use size hint (#579)

master
Niklas Fiekas 3 years ago committed by GitHub
parent 16cc1ce97c
commit 522b496738
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 26
      src/db.rs

@ -870,26 +870,22 @@ impl<T: ThreadMode> DBWithThreadMode<T> {
I: IntoIterator<Item = (&'b W, K)>,
W: AsColumnFamilyRef,
{
let mut boxed_keys: Vec<Box<[u8]>> = Vec::new();
let mut keys_sizes = Vec::new();
let mut column_families = Vec::new();
for (cf, key) in keys {
boxed_keys.push(Box::from(key.as_ref()));
keys_sizes.push(key.as_ref().len());
column_families.push(cf);
}
let ptr_keys: Vec<_> = boxed_keys
let (cfs_and_keys, keys_sizes): (Vec<(_, Box<[u8]>)>, Vec<_>) = keys
.into_iter()
.map(|(cf, key)| ((cf, Box::from(key.as_ref())), key.as_ref().len()))
.unzip();
let ptr_keys: Vec<_> = cfs_and_keys
.iter()
.map(|k| k.as_ptr() as *const c_char)
.map(|(_, k)| k.as_ptr() as *const c_char)
.collect();
let ptr_cfs: Vec<_> = column_families
let ptr_cfs: Vec<_> = cfs_and_keys
.iter()
.map(|c| c.inner() as *const _)
.map(|(c, _)| c.inner() as *const _)
.collect();
let mut values = vec![ptr::null_mut(); boxed_keys.len()];
let mut values_sizes = vec![0_usize; boxed_keys.len()];
let mut errors = vec![ptr::null_mut(); boxed_keys.len()];
let mut values = vec![ptr::null_mut(); ptr_keys.len()];
let mut values_sizes = vec![0_usize; ptr_keys.len()];
let mut errors = vec![ptr::null_mut(); ptr_keys.len()];
unsafe {
ffi::rocksdb_multi_get_cf(
self.inner,

Loading…
Cancel
Save