Skip to content

Commit

Permalink
hash shift to index
Browse files Browse the repository at this point in the history
  • Loading branch information
sagudev committed Mar 2, 2024
1 parent 7cbd668 commit 8e32c6e
Showing 1 changed file with 14 additions and 8 deletions.
22 changes: 14 additions & 8 deletions components/script/script_module.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@
//! The script module mod contains common traits and structs
//! related to `type=module` for script thread or worker threads.

use std::collections::{HashMap, HashSet};
type H = fnv::FnvBuildHasher;
type HashMap<K, V> = indexmap::IndexMap<K, V, H>;
type HashSet<K> = indexmap::IndexSet<K, H>;
use std::rc::Rc;
use std::str::FromStr;
use std::sync::{Arc, Mutex};
Expand Down Expand Up @@ -326,10 +328,14 @@ impl ModuleTree {
}

fn has_all_ready_descendants(&self, global: &GlobalScope) -> bool {
let module_map = global.get_module_map().borrow();
let mut discovered_urls = HashSet::new();
let mut module_map: HashMap<ServoUrl, Rc<ModuleTree>> = HashMap::with_hasher(H::default());
let m = global.get_module_map().borrow();
for (k, v) in &m.0 {
module_map.insert(k.clone(), v.clone());
}
let mut discovered_urls = HashSet::with_hasher(H::default());

return ModuleTree::recursive_check_descendants(&self, &module_map.0, &mut discovered_urls);
return ModuleTree::recursive_check_descendants(&self, &module_map, &mut discovered_urls);
}

// We just leverage the power of Promise to run the task for `finish` the owner.
Expand Down Expand Up @@ -822,7 +828,7 @@ impl ModuleTree {
}
}

let mut discovered_urls: HashSet<ServoUrl> = HashSet::new();
let mut discovered_urls: HashSet<ServoUrl> = HashSet::with_hasher(H::default());
let (network_error, rethrow_error) =
self.find_first_parse_error(&global, &mut discovered_urls);

Expand Down Expand Up @@ -1375,7 +1381,7 @@ fn fetch_an_import_module_script_graph(

let url = url.unwrap();

let mut visited_urls = HashSet::new();
let mut visited_urls = HashSet::with_hasher(H::default());
visited_urls.insert(url.clone());

fetch_single_module_script(
Expand Down Expand Up @@ -1485,7 +1491,7 @@ pub(crate) fn fetch_external_module_script(
destination: Destination,
options: ScriptFetchOptions,
) {
let mut visited_urls = HashSet::new();
let mut visited_urls = HashSet::with_hasher(H::default());
visited_urls.insert(url.clone());

// Step 1.
Expand Down Expand Up @@ -1712,7 +1718,7 @@ pub(crate) fn fetch_inline_module_script(
) {
let global = owner.global();
let is_external = false;
let module_tree = ModuleTree::new(url.clone(), is_external, HashSet::new());
let module_tree = ModuleTree::new(url.clone(), is_external, HashSet::with_hasher(H::default()));

let compiled_module = module_tree.compile_module_script(
&global,
Expand Down

0 comments on commit 8e32c6e

Please sign in to comment.