Skip to content

Commit

Permalink
further dataptah refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
misson20000 committed Oct 26, 2024
1 parent fb1ff28 commit 95a5b11
Show file tree
Hide file tree
Showing 7 changed files with 168 additions and 210 deletions.
72 changes: 3 additions & 69 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ adw = { version = "0.7.0", package = "libadwaita" }
toml = "0.8.19"
xdg = "2.5.2"
bitflags = "2.6.0"
ouroboros = "0.18.4"

[dev-dependencies]
pretty_assertions = "1.4.1"
Expand Down
93 changes: 64 additions & 29 deletions src/model/datapath.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
use std::iter;
use std::string;
use std::sync;
use std::vec;
Expand All @@ -14,23 +13,20 @@ pub struct FetchFlags(u8);

bitflags! {
impl FetchFlags: u8 {
/* Somewhere along the line, data wasn't yet, so try again later and if you're lucky it will be in the cache next time. */
const PENDING = 1;

/* Touched by a LoadSpaceEdit */
const LOADED = 2;
const LOADED = 1;

/* Touched by an OverwriteEdit */
const OVERWRITTEN = 4;
const OVERWRITTEN = 2;

/* Touched by an InsertEdit */
const INSERTED = 8;
const INSERTED = 4;

/* Touched by a MoveEdit or the trailing end of an InsertEdit */
const MOVED = 16;
const MOVED = 8;

/* Some kind of error was encountered, probably an I/O error. */
const ERROR = 32;
const ERROR = 16;
}
}

Expand All @@ -48,6 +44,13 @@ pub struct FetchResult {
loaded: u64,
}

type LoadFuture = std::pin::Pin<std::box::Box<impl std::future::Future<Output = FetchResult>>>;

enum FilterFetchResult<'a> {
Pass(FetchRequest<'a>),
Done(FetchResult),
}

enum RequestSlice<'a> {
NonOverlapping(FetchRequest<'a>),
OverlapsStart {
Expand Down Expand Up @@ -83,20 +86,9 @@ impl Filter {
}
}

async fn load_next<'a>(mut iter: impl iter::Iterator<Item = &'a Filter> + Clone, rq: FetchRequest<'_>) -> FetchResult {
if let Some(filter) = iter.next() {
filter.load(iter, rq).await
} else {
FetchResult {
flags: FetchFlags::default(),
loaded: rq.len(),
}
}
}

async fn load<'a>(&self, iter: impl iter::Iterator<Item = &'a Filter> + Clone, rq: FetchRequest<'_>) -> FetchResult {
async fn load<'a>(&self, rq: FetchRequest<'a>) -> FilterFetchResult<'a> {
match self {
Filter::LoadSpace(f) => todo!(),//f.load(iter, rq),
Filter::LoadSpace(f) => f.load(rq).await,
Filter::Overwrite(_f) => todo!(),//f.load(iter, rq),
Filter::Move(_f) => todo!(),//f.load(iter, rq),
Filter::Insert(_f) => todo!(),//f.load(iter, rq),
Expand Down Expand Up @@ -145,7 +137,17 @@ impl DataPathExt for DataPath {
flags.fill(FetchFlags::default());
}

Filter::load_next(sc.iter().rev(), rq).await
for filter in sc.iter().rev() {
rq = match filter.load(std::mem::replace(&mut rq, FetchRequest::default())).await {
FilterFetchResult::Pass(rq) => rq,
FilterFetchResult::Done(rs) => return rs,
}
}

FetchResult {
flags: FetchFlags::default(),
loaded: rq.len(),
}
}
}

Expand Down Expand Up @@ -422,18 +424,51 @@ impl LoadSpaceFilter {
}
*/

async fn load<'a>(&self, iter: impl iter::Iterator<Item = &'a Filter> + Clone, rq: FetchRequest<'_>) -> FetchResult {
let (before, overlap, after) = rq.split3(self.load_offset, self.size);
async fn load<'a>(&self, rq: FetchRequest<'a>) -> FilterFetchResult<'a> {
let (before, mut overlap, after) = rq.split3(self.load_offset, self.size);

if !before.is_empty() {
return Filter::load_next(iter, before).await;
return FilterFetchResult::Pass(before);
}

if !overlap.is_empty() {
todo!();
//self.cache.fetch_block();
let block_addr = (overlap.addr / self.cache.block_size) * self.cache.block_size;
return FilterFetchResult::Done(self.cache.fetch_block(block_addr, |fr| {
match fr {
space::FetchResult::Ok(v) | space::FetchResult::Partial(v) => {
let begin_index = (overlap.addr - block_addr) as usize;
let loaded_count = (std::cmp::min(overlap.end() - block_addr, v.len() as u64) - (overlap.addr - block_addr)) as usize;

overlap.data[0..loaded_count].copy_from_slice(&v[begin_index..(begin_index+loaded_count)]);

if let Some(flags) = overlap.flags.as_mut() {
for f in &mut flags[0..loaded_count] {
*f|= FetchFlags::LOADED;
}
}

FetchResult {
flags: FetchFlags::LOADED,
loaded: loaded_count as u64,
}
},
space::FetchResult::Unreadable | space::FetchResult::IoError(_) => {
if let Some(flags) = overlap.flags.as_mut() {
for f in flags.iter_mut() {
*f|= FetchFlags::LOADED | FetchFlags::ERROR;
}
}

FetchResult {
flags: FetchFlags::LOADED | FetchFlags::ERROR,
loaded: overlap.len(),
}
},
}
}).await);
}

return Filter::load_next(iter, after).await;
FilterFetchResult::Pass(after)
}

fn human_details(&self) -> string::String {
Expand Down
13 changes: 9 additions & 4 deletions src/model/listing/cursor/hexdump.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,10 @@ pub struct Cursor {
pub offset: addr::Size,
pub low_nybble: bool,

data_cache: vec::Vec<datapath::ByteRecord>,
data_pending: bool,
data: vec::Vec<u8>,
flags: vec::Vec<datapath::FetchFlags>,
data_loaded: usize,
data_future: Option<datapath::LoadFuture>,
}

impl Cursor {
Expand Down Expand Up @@ -82,8 +84,10 @@ impl Cursor {
_ => false,
},

data_cache: vec::Vec::new(),
data_pending: true,
data: vec::Vec::new(),
flags: vec::Vec::new(),
data_loaded: 0,
data_future: None,
})
}

Expand Down Expand Up @@ -225,6 +229,7 @@ impl cursor::CursorClassExt for Cursor {
}

fn work(&mut self, document: &document::Document, cx: &mut task::Context) -> bool {
if self.data_loaded <
if self.data_pending {
let (begin_byte, size) = self.token.absolute_extent().round_out();

Expand Down
8 changes: 4 additions & 4 deletions src/model/mod.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
pub mod addr;
pub mod datapath;
//pub mod document;
//pub mod listing;
//pub mod selection;
pub mod document;
pub mod listing;
pub mod selection;
pub mod space;
//pub mod versioned;
pub mod versioned;
11 changes: 11 additions & 0 deletions src/model/space.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use std::sync;
use std::vec;

pub mod cache;
Expand All @@ -20,6 +21,16 @@ pub enum AddressSpace {
File(file::FileAddressSpace)
}

impl AddressSpace {
fn fetch_owned(self: sync::Arc<Self>, extent: (u64, u64)) -> impl std::future::Future<Output = FetchResult> + 'static {
async move {
match &*self {
AddressSpace::File(fas) => fas.fetch(extent).await,
}
}
}
}

impl AddressSpaceExt for AddressSpace {
fn get_label(&self) -> &str {
match self {
Expand Down
Loading

0 comments on commit 95a5b11

Please sign in to comment.