vec: make collect_range use into_iter

This commit is contained in:
nym21
2025-04-27 10:39:14 +02:00
parent bdc3c19163
commit 1e38c21f8e
4 changed files with 21 additions and 30 deletions

View File

@@ -75,3 +75,4 @@ Stores: `src/storage/stores/mod.rs`
- mode: `raw`
- disk usage: `208 GB`
- overhead: `28%` (`208 GB / 744 GB`)
- peak memory: `5.7GB`

View File

@@ -10,7 +10,6 @@ use axum::{
response::{IntoResponse, Response},
};
use memmap2::Mmap;
use serde_json::Value;
use crate::{Error, Result, Version};
@@ -161,7 +160,11 @@ where
}
#[inline]
fn collect_range_serde_json(&self, from: Option<i64>, to: Option<i64>) -> Result<Vec<Value>> {
fn collect_range_serde_json(
&self,
from: Option<i64>,
to: Option<i64>,
) -> Result<Vec<serde_json::Value>> {
self.collect_signed_range(from, to)?
.into_iter()
.map(|v| serde_json::to_value(v).map_err(Error::from))

View File

@@ -324,30 +324,21 @@ where
})
}
fn collect_range(&self, from: Option<usize>, to: Option<usize>) -> Result<Vec<Self::T>> {
if !self.is_pushed_empty() {
return Err(Error::UnsupportedUnflushedState);
}
fn collect_range(&self, from: Option<usize>, to: Option<usize>) -> Result<Vec<T>> {
let stored_len = self.stored_len();
let from = from.unwrap_or_default();
let to = to.map_or(stored_len, |i| i.min(stored_len));
if from >= stored_len {
if from >= stored_len || from >= to {
return Ok(vec![]);
}
let mmap = self.mmap().load();
let pages_meta = self.pages_meta.load();
let mut decoded_page: Option<(usize, Vec<T>)> = None;
(from..to)
.map(|index| {
Self::cached_get_stored__(index, &mmap, stored_len, &mut decoded_page, &pages_meta)
.map(|opt| opt.unwrap())
})
.collect::<Result<Vec<_>>>()
Ok(self
.into_iter()
.skip(from)
.take(to - from)
.map(|(_, v)| v.into_inner())
.collect::<Vec<_>>())
}
fn flush(&mut self) -> Result<()> {

View File

@@ -152,24 +152,20 @@ where
}
fn collect_range(&self, from: Option<usize>, to: Option<usize>) -> Result<Vec<T>> {
if !self.is_pushed_empty() {
return Err(Error::UnsupportedUnflushedState);
}
let stored_len = self.stored_len();
let from = from.unwrap_or_default();
let to = to.map_or(stored_len, |i| i.min(stored_len));
if from >= stored_len {
if from >= stored_len || from >= to {
return Ok(vec![]);
}
let mmap = self.mmap.load();
(from..to)
.map(|index| self.get_stored_(index, &mmap).map(|opt| opt.unwrap()))
.collect::<Result<Vec<_>>>()
Ok(self
.into_iter()
.skip(from)
.take(to - from)
.map(|(_, v)| v.into_inner())
.collect::<Vec<_>>())
}
fn flush(&mut self) -> Result<()> {