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

Loading…
Cancel
Save