mirror of
https://github.com/servo/servo.git
synced 2025-07-23 07:13:52 +01:00
Avoid unnecessary clones for URLs (#32694)
This commit is contained in:
parent
d9b99723f5
commit
956b7f62e0
1 changed files with 29 additions and 27 deletions
|
@ -273,14 +273,16 @@ impl ModuleTree {
|
||||||
self.parent_identities.borrow_mut().insert(parent_identity);
|
self.parent_identities.borrow_mut().insert(parent_identity);
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn insert_incomplete_fetch_url(&self, dependency: ServoUrl) {
|
pub fn insert_incomplete_fetch_url(&self, dependency: &ServoUrl) {
|
||||||
self.incomplete_fetch_urls.borrow_mut().insert(dependency);
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn remove_incomplete_fetch_url(&self, dependency: ServoUrl) {
|
|
||||||
self.incomplete_fetch_urls
|
self.incomplete_fetch_urls
|
||||||
.borrow_mut()
|
.borrow_mut()
|
||||||
.shift_remove(&dependency);
|
.insert(dependency.clone());
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn remove_incomplete_fetch_url(&self, dependency: &ServoUrl) {
|
||||||
|
self.incomplete_fetch_urls
|
||||||
|
.borrow_mut()
|
||||||
|
.shift_remove(dependency);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// recursively checks if all of the transitive descendants are
|
/// recursively checks if all of the transitive descendants are
|
||||||
|
@ -421,7 +423,7 @@ impl ModuleTree {
|
||||||
global: &GlobalScope,
|
global: &GlobalScope,
|
||||||
owner: ModuleOwner,
|
owner: ModuleOwner,
|
||||||
module_script_text: Rc<DOMString>,
|
module_script_text: Rc<DOMString>,
|
||||||
url: ServoUrl,
|
url: &ServoUrl,
|
||||||
options: ScriptFetchOptions,
|
options: ScriptFetchOptions,
|
||||||
) -> Result<ModuleObject, RethrowError> {
|
) -> Result<ModuleObject, RethrowError> {
|
||||||
let cx = GlobalScope::get_cx();
|
let cx = GlobalScope::get_cx();
|
||||||
|
@ -460,7 +462,7 @@ impl ModuleTree {
|
||||||
self.resolve_requested_module_specifiers(
|
self.resolve_requested_module_specifiers(
|
||||||
global,
|
global,
|
||||||
module_script.handle().into_handle(),
|
module_script.handle().into_handle(),
|
||||||
url.clone(),
|
url,
|
||||||
)
|
)
|
||||||
.map(|_| ModuleObject(Heap::boxed(*module_script)))
|
.map(|_| ModuleObject(Heap::boxed(*module_script)))
|
||||||
}
|
}
|
||||||
|
@ -559,7 +561,7 @@ impl ModuleTree {
|
||||||
&self,
|
&self,
|
||||||
global: &GlobalScope,
|
global: &GlobalScope,
|
||||||
module_object: HandleObject,
|
module_object: HandleObject,
|
||||||
base_url: ServoUrl,
|
base_url: &ServoUrl,
|
||||||
) -> Result<IndexSet<ServoUrl>, RethrowError> {
|
) -> Result<IndexSet<ServoUrl>, RethrowError> {
|
||||||
let cx = GlobalScope::get_cx();
|
let cx = GlobalScope::get_cx();
|
||||||
let _ac = JSAutoRealm::new(*cx, *global.reflector().get_jsobject());
|
let _ac = JSAutoRealm::new(*cx, *global.reflector().get_jsobject());
|
||||||
|
@ -623,7 +625,7 @@ impl ModuleTree {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Step 3.
|
// Step 3.
|
||||||
ServoUrl::parse_with_base(Some(url), &specifier_str.clone())
|
ServoUrl::parse_with_base(Some(url), &specifier_str)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <https://html.spec.whatwg.org/multipage/#finding-the-first-parse-error>
|
/// <https://html.spec.whatwg.org/multipage/#finding-the-first-parse-error>
|
||||||
|
@ -692,7 +694,7 @@ impl ModuleTree {
|
||||||
options: &ScriptFetchOptions,
|
options: &ScriptFetchOptions,
|
||||||
parent_identity: ModuleIdentity,
|
parent_identity: ModuleIdentity,
|
||||||
) {
|
) {
|
||||||
debug!("Start to load dependencies of {}", self.url.clone());
|
debug!("Start to load dependencies of {}", self.url);
|
||||||
|
|
||||||
let global = owner.global();
|
let global = owner.global();
|
||||||
|
|
||||||
|
@ -706,7 +708,7 @@ impl ModuleTree {
|
||||||
self.set_status(ModuleStatus::Finished);
|
self.set_status(ModuleStatus::Finished);
|
||||||
debug!(
|
debug!(
|
||||||
"Module {} doesn't have module record but tried to load descendants.",
|
"Module {} doesn't have module record but tried to load descendants.",
|
||||||
self.url.clone()
|
self.url
|
||||||
);
|
);
|
||||||
return;
|
return;
|
||||||
},
|
},
|
||||||
|
@ -714,7 +716,7 @@ impl ModuleTree {
|
||||||
Some(raw_record) => self.resolve_requested_module_specifiers(
|
Some(raw_record) => self.resolve_requested_module_specifiers(
|
||||||
&global,
|
&global,
|
||||||
raw_record.handle(),
|
raw_record.handle(),
|
||||||
self.url.clone(),
|
&self.url,
|
||||||
),
|
),
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
@ -722,7 +724,7 @@ impl ModuleTree {
|
||||||
match specifier_urls {
|
match specifier_urls {
|
||||||
// Step 3.
|
// Step 3.
|
||||||
Ok(valid_specifier_urls) if valid_specifier_urls.is_empty() => {
|
Ok(valid_specifier_urls) if valid_specifier_urls.is_empty() => {
|
||||||
debug!("Module {} doesn't have any dependencies.", self.url.clone());
|
debug!("Module {} doesn't have any dependencies.", self.url);
|
||||||
self.advance_finished_and_link(&global);
|
self.advance_finished_and_link(&global);
|
||||||
},
|
},
|
||||||
Ok(valid_specifier_urls) => {
|
Ok(valid_specifier_urls) => {
|
||||||
|
@ -741,7 +743,7 @@ impl ModuleTree {
|
||||||
// Step 5-3-2.
|
// Step 5-3-2.
|
||||||
visited_urls.insert(parsed_url.clone());
|
visited_urls.insert(parsed_url.clone());
|
||||||
|
|
||||||
self.insert_incomplete_fetch_url(parsed_url.clone());
|
self.insert_incomplete_fetch_url(&parsed_url);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -749,7 +751,7 @@ impl ModuleTree {
|
||||||
if urls.is_empty() {
|
if urls.is_empty() {
|
||||||
debug!(
|
debug!(
|
||||||
"After checking with visited urls, module {} doesn't have dependencies to load.",
|
"After checking with visited urls, module {} doesn't have dependencies to load.",
|
||||||
self.url.clone()
|
&self.url
|
||||||
);
|
);
|
||||||
self.advance_finished_and_link(&global);
|
self.advance_finished_and_link(&global);
|
||||||
return;
|
return;
|
||||||
|
@ -767,7 +769,7 @@ impl ModuleTree {
|
||||||
// Step 2.
|
// Step 2.
|
||||||
fetch_single_module_script(
|
fetch_single_module_script(
|
||||||
owner.clone(),
|
owner.clone(),
|
||||||
url.clone(),
|
url,
|
||||||
visited_urls.clone(),
|
visited_urls.clone(),
|
||||||
destination,
|
destination,
|
||||||
options,
|
options,
|
||||||
|
@ -795,7 +797,7 @@ impl ModuleTree {
|
||||||
|
|
||||||
self.set_status(ModuleStatus::Finished);
|
self.set_status(ModuleStatus::Finished);
|
||||||
|
|
||||||
debug!("Going to advance and finish for: {}", self.url.clone());
|
debug!("Going to advance and finish for: {}", self.url);
|
||||||
|
|
||||||
{
|
{
|
||||||
// Notify parents of this module to finish
|
// Notify parents of this module to finish
|
||||||
|
@ -812,8 +814,8 @@ impl ModuleTree {
|
||||||
};
|
};
|
||||||
|
|
||||||
if incomplete_count_before_remove > 0 {
|
if incomplete_count_before_remove > 0 {
|
||||||
parent_tree.remove_incomplete_fetch_url(self.url.clone());
|
parent_tree.remove_incomplete_fetch_url(&self.url);
|
||||||
parent_tree.advance_finished_and_link(global);
|
parent_tree.advance_finished_and_link(&global);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -829,7 +831,7 @@ impl ModuleTree {
|
||||||
(None, None) => {
|
(None, None) => {
|
||||||
let module_record = self.get_record().borrow();
|
let module_record = self.get_record().borrow();
|
||||||
if let Some(record) = &*module_record {
|
if let Some(record) = &*module_record {
|
||||||
let instantiated = self.instantiate_module_tree(global, record.handle());
|
let instantiated = self.instantiate_module_tree(&global, record.handle());
|
||||||
|
|
||||||
if let Err(exception) = instantiated {
|
if let Err(exception) = instantiated {
|
||||||
self.set_rethrow_error(exception);
|
self.set_rethrow_error(exception);
|
||||||
|
@ -1129,15 +1131,15 @@ impl FetchResponseListener for ModuleContext {
|
||||||
|
|
||||||
let module_tree = {
|
let module_tree = {
|
||||||
let module_map = global.get_module_map().borrow();
|
let module_map = global.get_module_map().borrow();
|
||||||
module_map.get(&self.url.clone()).unwrap().clone()
|
module_map.get(&self.url).unwrap().clone()
|
||||||
};
|
};
|
||||||
|
|
||||||
module_tree.remove_incomplete_fetch_url(self.url.clone());
|
module_tree.remove_incomplete_fetch_url(&self.url);
|
||||||
|
|
||||||
// Step 12.
|
// Step 12.
|
||||||
match load {
|
match load {
|
||||||
Err(err) => {
|
Err(err) => {
|
||||||
error!("Failed to fetch {} with error {:?}", self.url.clone(), err);
|
error!("Failed to fetch {} with error {:?}", &self.url, err);
|
||||||
module_tree.set_network_error(err);
|
module_tree.set_network_error(err);
|
||||||
module_tree.advance_finished_and_link(&global);
|
module_tree.advance_finished_and_link(&global);
|
||||||
},
|
},
|
||||||
|
@ -1148,7 +1150,7 @@ impl FetchResponseListener for ModuleContext {
|
||||||
&global,
|
&global,
|
||||||
self.owner.clone(),
|
self.owner.clone(),
|
||||||
resp_mod_script.text(),
|
resp_mod_script.text(),
|
||||||
self.url.clone(),
|
&self.url,
|
||||||
self.options.clone(),
|
self.options.clone(),
|
||||||
);
|
);
|
||||||
|
|
||||||
|
@ -1627,7 +1629,7 @@ fn fetch_single_module_script(
|
||||||
module_tree.insert_parent_identity(parent_identity);
|
module_tree.insert_parent_identity(parent_identity);
|
||||||
}
|
}
|
||||||
|
|
||||||
module_tree.insert_incomplete_fetch_url(url.clone());
|
module_tree.insert_incomplete_fetch_url(&url);
|
||||||
|
|
||||||
// Step 4.
|
// Step 4.
|
||||||
global.set_module_map(url.clone(), module_tree);
|
global.set_module_map(url.clone(), module_tree);
|
||||||
|
@ -1714,7 +1716,7 @@ pub(crate) fn fetch_inline_module_script(
|
||||||
&global,
|
&global,
|
||||||
owner.clone(),
|
owner.clone(),
|
||||||
module_script_text,
|
module_script_text,
|
||||||
url.clone(),
|
&url,
|
||||||
options.clone(),
|
options.clone(),
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue