Skip to content

Commit

Permalink
Remove temporary boxed keys in batched_multi_get (#801)
Browse files Browse the repository at this point in the history
  • Loading branch information
axnsan12 committed Jul 15, 2023
1 parent c62c8c2 commit f8906c3
Showing 1 changed file with 12 additions and 10 deletions.
22 changes: 12 additions & 10 deletions src/db.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1173,38 +1173,40 @@ impl<T: ThreadMode, D: DBInner> DBCommon<T, D> {
/// Return the values associated with the given keys and the specified column family
/// where internally the read requests are processed in batch if block-based table
/// SST format is used. It is a more optimized version of multi_get_cf.
pub fn batched_multi_get_cf<K, I>(
pub fn batched_multi_get_cf<'a, K, I>(
&self,
cf: &impl AsColumnFamilyRef,
keys: I,
sorted_input: bool,
) -> Vec<Result<Option<DBPinnableSlice>, Error>>
where
K: AsRef<[u8]>,
I: IntoIterator<Item = K>,
K: AsRef<[u8]> + 'a + ?Sized,
I: IntoIterator<Item = &'a K>,
{
self.batched_multi_get_cf_opt(cf, keys, sorted_input, &ReadOptions::default())
}

/// Return the values associated with the given keys and the specified column family
/// where internally the read requests are processed in batch if block-based table
/// SST format is used. It is a more optimized version of multi_get_cf_opt.
pub fn batched_multi_get_cf_opt<K, I>(
/// SST format is used. It is a more optimized version of multi_get_cf_opt.
pub fn batched_multi_get_cf_opt<'a, K, I>(
&self,
cf: &impl AsColumnFamilyRef,
keys: I,
sorted_input: bool,
readopts: &ReadOptions,
) -> Vec<Result<Option<DBPinnableSlice>, Error>>
where
K: AsRef<[u8]>,
I: IntoIterator<Item = K>,
K: AsRef<[u8]> + 'a + ?Sized,
I: IntoIterator<Item = &'a K>,
{
let (keys, keys_sizes): (Vec<Box<[u8]>>, Vec<_>) = keys
let (ptr_keys, keys_sizes): (Vec<_>, Vec<_>) = keys
.into_iter()
.map(|k| (Box::from(k.as_ref()), k.as_ref().len()))
.map(|k| {
let k = k.as_ref();
(k.as_ptr() as *const c_char, k.len())
})
.unzip();
let ptr_keys: Vec<_> = keys.iter().map(|k| k.as_ptr() as *const c_char).collect();

let mut pinned_values = vec![ptr::null_mut(); ptr_keys.len()];
let mut errors = vec![ptr::null_mut(); ptr_keys.len()];
Expand Down

0 comments on commit f8906c3

Please sign in to comment.