Range reads M0/M1 (indexed lookups, Storage trait), ZFP, in-place editing #17
@@ -198,6 +198,14 @@ pub fn read_exact_at(
|
||||
.saturating_add(len),
|
||||
available: len_usize(file),
|
||||
};
|
||||
// In-memory fast path: one dynamic call, then plain slicing.
|
||||
if let Some(all) = file.as_contiguous() {
|
||||
return usize::try_from(offset)
|
||||
.ok()
|
||||
.and_then(|start| all.get(start..start.checked_add(len)?))
|
||||
.map(Cow::Borrowed)
|
||||
.ok_or_else(eof);
|
||||
}
|
||||
match offset.checked_add(len as u64) {
|
||||
Some(end) if end <= file.len() => {}
|
||||
_ => return Err(eof()),
|
||||
@@ -271,6 +279,11 @@ pub fn read_upto(
|
||||
offset: u64,
|
||||
max: usize,
|
||||
) -> Result<Cow<'_, [u8]>, FormatError> {
|
||||
if let Some(all) = file.as_contiguous() {
|
||||
let start = usize::try_from(offset).map_or(all.len(), |o| o.min(all.len()));
|
||||
let end = start.saturating_add(max).min(all.len());
|
||||
return Ok(Cow::Borrowed(&all[start..end]));
|
||||
}
|
||||
let avail = file.len().saturating_sub(offset);
|
||||
let len = usize::try_from(avail).map_or(max, |a| a.min(max));
|
||||
let bytes = file.read_at(offset, len)?;
|
||||
|
||||
Reference in New Issue
Block a user