Skip to content

Commit

Permalink
Replace size property with associated function
Browse files Browse the repository at this point in the history
  • Loading branch information
KrisChambers committed Jul 25, 2020
1 parent 1d73ec6 commit cc69c29
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 12 deletions.
23 changes: 19 additions & 4 deletions cli/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ impl FileInfoDepTree {
.get(&name)
.unwrap();

let size = file.size;
let size = file.size();

let deps = if never_seen {
file
Expand Down Expand Up @@ -329,16 +329,31 @@ fn print_dep (
info: &FileInfoDepTree,
) {
let has_children = !info.deps.is_empty();
println!("{}{}─{} {} ({}, total = {})",
let totals = get_totals_string(info);

println!("{}{}─{} {}{}",
prefix,
get_sibling_connector(is_last),
get_child_connector(has_children),
info.name,
human_size(info.size as f64),
human_size(info.total_size as f64)
totals
);
}

fn get_totals_string(
info: &FileInfoDepTree
) -> String {
if info.total_size == 0 {
"".to_string()
} else {
format!(
" ({}, total = {})",
human_size(info.size as f64),
human_size(info.total_size as f64)
)
}
}

/// Gets the sibling portion of the tree branch.
fn get_sibling_connector(is_last: bool) -> char {
if is_last {
Expand Down
15 changes: 7 additions & 8 deletions cli/module_graph.rs
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,12 @@ pub struct ModuleGraphFile {
pub type_headers: Vec<ReferenceDescriptor>,
pub media_type: MediaType,
pub source_code: String,
pub size: usize,
}

impl ModuleGraphFile {
pub fn size(&self) -> usize {
self.source_code.as_bytes().len()
}
}

type SourceFileFuture =
Expand Down Expand Up @@ -366,8 +371,6 @@ impl ModuleGraphLoader {
}
}

let size = source_code.as_bytes().len();

self.graph.insert(
module_specifier.to_string(),
ModuleGraphFile {
Expand All @@ -383,8 +386,7 @@ impl ModuleGraphLoader {
lib_directives,
types_directives,
type_headers: vec![],
size,
},
}
);
Ok(())
}
Expand Down Expand Up @@ -472,13 +474,11 @@ impl ModuleGraphLoader {
lib_directives: vec![],
types_directives: vec![],
type_headers: vec![],
size: 0,
},
);
}

let module_specifier = ModuleSpecifier::from(source_file.url.clone());
let size = source_file.source_code.len();
let version_hash =
checksum::gen(&[&source_file.source_code, version::DENO.as_bytes()]);
let source_code = String::from_utf8(source_file.source_code)?;
Expand Down Expand Up @@ -577,7 +577,6 @@ impl ModuleGraphLoader {
lib_directives,
types_directives,
type_headers,
size,
},
);
Ok(())
Expand Down

0 comments on commit cc69c29

Please sign in to comment.