Skip to content

Commit

Permalink
Merge pull request #95 from yuma140902/remove-byte-map-from-resource
Browse files Browse the repository at this point in the history
refactor: remove byte_map in `Resource`
  • Loading branch information
yuma140902 authored Dec 18, 2023
2 parents ce516ea + ec747e2 commit 511e6bf
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 28 deletions.
20 changes: 1 addition & 19 deletions src/pipeline.rs
Original file line number Diff line number Diff line change
Expand Up @@ -81,27 +81,9 @@ impl Pipeline {
let _enter = step_span.enter();
debug!("start");
match step {
Step::Load { key, with, .. } => {
Step::Load { key, .. } => {
if let Some(value) = resource.get_value(&index) {
store.set(key.to_string(), value.clone());
} else if let Some(bytes) = resource.get_bytes(&index) {
let value = match with {
EnumLoader::Template => TemplateLoader::load(bytes),
EnumLoader::Json => JsonLoader::load(bytes),
EnumLoader::TextWithFrontmatter => {
TextWithFrontmatterLoader::load(bytes)
}
EnumLoader::Blob => BlobLoader::load(bytes),
EnumLoader::Text => TextLoader::load(bytes),
EnumLoader::Yaml => YamlLoader::load(bytes),
}
.with_context(|| {
format!(
"failed to load {} with {:?} Loader (steps index: {})",
key, self.entry.type_, index
)
})?;
store.set(key.to_string(), value);
} else {
anyhow::bail!("no value prefetched for key {}", key);
}
Expand Down
10 changes: 1 addition & 9 deletions src/pipeline/resource.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ use super::Pipeline;
/// One resource instance is created per [`Pipeline`](crate::pipeline::Pipeline).
#[derive(Debug)]
pub struct Resource {
byte_map: HashMap<usize, Vec<u8>>,
value_map: HashMap<usize, Value>,
}

Expand Down Expand Up @@ -59,14 +58,7 @@ impl Resource {
info!("finish preload");
}
}
Ok(Self {
byte_map,
value_map,
})
}

pub fn get_bytes(&self, key: &usize) -> Option<&[u8]> {
self.byte_map.get(key).map(|v| &v[..])
Ok(Self { value_map })
}

pub fn get_value(&self, key: &usize) -> Option<&Value> {
Expand Down

0 comments on commit 511e6bf

Please sign in to comment.