mirror of
https://github.com/servo/servo.git
synced 2025-06-13 19:04:30 +00:00
Use IndexSet for storing descendants
Fixes intermittent failures in `/html/semantics/scripting-1/the-script-element/module/choice-of-error-1.html`
This commit is contained in:
parent
e7bc0fae4c
commit
9460b43f90
2 changed files with 31 additions and 12 deletions
|
@ -311,6 +311,15 @@ unsafe impl<T: JSTraceable> JSTraceable for VecDeque<T> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
unsafe impl<T: JSTraceable + Eq + Hash> JSTraceable for indexmap::IndexSet<T> {
|
||||||
|
#[inline]
|
||||||
|
unsafe fn trace(&self, trc: *mut JSTracer) {
|
||||||
|
for e in self.iter() {
|
||||||
|
e.trace(trc);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
unsafe impl<A, B, C, D> JSTraceable for (A, B, C, D)
|
unsafe impl<A, B, C, D> JSTraceable for (A, B, C, D)
|
||||||
where
|
where
|
||||||
A: JSTraceable,
|
A: JSTraceable,
|
||||||
|
|
|
@ -70,6 +70,8 @@ use std::rc::Rc;
|
||||||
use std::sync::{Arc, Mutex};
|
use std::sync::{Arc, Mutex};
|
||||||
use url::ParseError as UrlParseError;
|
use url::ParseError as UrlParseError;
|
||||||
|
|
||||||
|
use indexmap::IndexSet;
|
||||||
|
|
||||||
pub fn get_source_text(source: &[u16]) -> SourceText<u16> {
|
pub fn get_source_text(source: &[u16]) -> SourceText<u16> {
|
||||||
SourceText {
|
SourceText {
|
||||||
units_: source.as_ptr() as *const _,
|
units_: source.as_ptr() as *const _,
|
||||||
|
@ -162,8 +164,16 @@ pub struct ModuleTree {
|
||||||
text: DomRefCell<DOMString>,
|
text: DomRefCell<DOMString>,
|
||||||
record: DomRefCell<Option<ModuleObject>>,
|
record: DomRefCell<Option<ModuleObject>>,
|
||||||
status: DomRefCell<ModuleStatus>,
|
status: DomRefCell<ModuleStatus>,
|
||||||
parent_urls: DomRefCell<HashSet<ServoUrl>>,
|
// The spec maintains load order for descendants, so we use an indexset for descendants and
|
||||||
descendant_urls: DomRefCell<HashSet<ServoUrl>>,
|
// parents. This isn't actually necessary for parents however the IndexSet APIs don't
|
||||||
|
// interop with HashSet, and IndexSet isn't very expensive
|
||||||
|
// (https://github.com/bluss/indexmap/issues/110)
|
||||||
|
//
|
||||||
|
// By default all maps in web specs are ordered maps
|
||||||
|
// (https://infra.spec.whatwg.org/#ordered-map), however we can usually get away with using
|
||||||
|
// stdlib maps and sets because we rarely iterate over them.
|
||||||
|
parent_urls: DomRefCell<IndexSet<ServoUrl>>,
|
||||||
|
descendant_urls: DomRefCell<IndexSet<ServoUrl>>,
|
||||||
visited_urls: DomRefCell<HashSet<ServoUrl>>,
|
visited_urls: DomRefCell<HashSet<ServoUrl>>,
|
||||||
error: DomRefCell<Option<ModuleError>>,
|
error: DomRefCell<Option<ModuleError>>,
|
||||||
promise: DomRefCell<Option<Rc<Promise>>>,
|
promise: DomRefCell<Option<Rc<Promise>>>,
|
||||||
|
@ -176,8 +186,8 @@ impl ModuleTree {
|
||||||
text: DomRefCell::new(DOMString::new()),
|
text: DomRefCell::new(DOMString::new()),
|
||||||
record: DomRefCell::new(None),
|
record: DomRefCell::new(None),
|
||||||
status: DomRefCell::new(ModuleStatus::Initial),
|
status: DomRefCell::new(ModuleStatus::Initial),
|
||||||
parent_urls: DomRefCell::new(HashSet::new()),
|
parent_urls: DomRefCell::new(IndexSet::new()),
|
||||||
descendant_urls: DomRefCell::new(HashSet::new()),
|
descendant_urls: DomRefCell::new(IndexSet::new()),
|
||||||
visited_urls: DomRefCell::new(HashSet::new()),
|
visited_urls: DomRefCell::new(HashSet::new()),
|
||||||
error: DomRefCell::new(None),
|
error: DomRefCell::new(None),
|
||||||
promise: DomRefCell::new(None),
|
promise: DomRefCell::new(None),
|
||||||
|
@ -224,7 +234,7 @@ impl ModuleTree {
|
||||||
*self.text.borrow_mut() = module_text;
|
*self.text.borrow_mut() = module_text;
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn get_parent_urls(&self) -> &DomRefCell<HashSet<ServoUrl>> {
|
pub fn get_parent_urls(&self) -> &DomRefCell<IndexSet<ServoUrl>> {
|
||||||
&self.parent_urls
|
&self.parent_urls
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -232,15 +242,15 @@ impl ModuleTree {
|
||||||
self.parent_urls.borrow_mut().insert(parent_url);
|
self.parent_urls.borrow_mut().insert(parent_url);
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn append_parent_urls(&self, parent_urls: HashSet<ServoUrl>) {
|
pub fn append_parent_urls(&self, parent_urls: IndexSet<ServoUrl>) {
|
||||||
self.parent_urls.borrow_mut().extend(parent_urls);
|
self.parent_urls.borrow_mut().extend(parent_urls);
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn get_descendant_urls(&self) -> &DomRefCell<HashSet<ServoUrl>> {
|
pub fn get_descendant_urls(&self) -> &DomRefCell<IndexSet<ServoUrl>> {
|
||||||
&self.descendant_urls
|
&self.descendant_urls
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn append_descendant_urls(&self, descendant_urls: HashSet<ServoUrl>) {
|
pub fn append_descendant_urls(&self, descendant_urls: IndexSet<ServoUrl>) {
|
||||||
self.descendant_urls.borrow_mut().extend(descendant_urls);
|
self.descendant_urls.borrow_mut().extend(descendant_urls);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -474,7 +484,7 @@ impl ModuleTree {
|
||||||
pub fn resolve_requested_modules(
|
pub fn resolve_requested_modules(
|
||||||
&self,
|
&self,
|
||||||
global: &GlobalScope,
|
global: &GlobalScope,
|
||||||
) -> Result<HashSet<ServoUrl>, ModuleError> {
|
) -> Result<IndexSet<ServoUrl>, ModuleError> {
|
||||||
let status = self.get_status();
|
let status = self.get_status();
|
||||||
|
|
||||||
assert_ne!(status, ModuleStatus::Initial);
|
assert_ne!(status, ModuleStatus::Initial);
|
||||||
|
@ -503,7 +513,7 @@ impl ModuleTree {
|
||||||
None
|
None
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
.collect::<HashSet<ServoUrl>>()
|
.collect::<IndexSet<ServoUrl>>()
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -516,10 +526,10 @@ impl ModuleTree {
|
||||||
global: &GlobalScope,
|
global: &GlobalScope,
|
||||||
module_object: HandleObject,
|
module_object: HandleObject,
|
||||||
base_url: ServoUrl,
|
base_url: ServoUrl,
|
||||||
) -> Result<HashSet<ServoUrl>, ModuleError> {
|
) -> Result<IndexSet<ServoUrl>, ModuleError> {
|
||||||
let _ac = JSAutoRealm::new(*global.get_cx(), *global.reflector().get_jsobject());
|
let _ac = JSAutoRealm::new(*global.get_cx(), *global.reflector().get_jsobject());
|
||||||
|
|
||||||
let mut specifier_urls = HashSet::new();
|
let mut specifier_urls = IndexSet::new();
|
||||||
|
|
||||||
unsafe {
|
unsafe {
|
||||||
rooted!(in(*global.get_cx()) let requested_modules = GetRequestedModules(*global.get_cx(), module_object));
|
rooted!(in(*global.get_cx()) let requested_modules = GetRequestedModules(*global.get_cx(), module_object));
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue