mirror of
https://github.com/servo/servo.git
synced 2025-08-03 04:30:10 +01:00
Use IndexMap
for WebIDL Record
This commit is contained in:
parent
4ba0ab7bd0
commit
115b73f636
4 changed files with 27 additions and 9 deletions
|
@ -7,6 +7,7 @@
|
|||
use crate::dom::bindings::conversions::jsid_to_string;
|
||||
use crate::dom::bindings::error::report_pending_exception;
|
||||
use crate::dom::bindings::str::DOMString;
|
||||
use indexmap::IndexMap;
|
||||
use js::conversions::{ConversionResult, FromJSValConvertible, ToJSValConvertible};
|
||||
use js::jsapi::JSContext;
|
||||
use js::jsapi::JS_NewPlainObject;
|
||||
|
@ -22,28 +23,27 @@ use js::rust::wrappers::JS_GetPropertyById;
|
|||
use js::rust::HandleValue;
|
||||
use js::rust::IdVector;
|
||||
use js::rust::MutableHandleValue;
|
||||
use std::collections::HashMap;
|
||||
use std::ops::Deref;
|
||||
|
||||
/// The `MozMap` (open-ended dictionary) type.
|
||||
#[derive(Clone, JSTraceable)]
|
||||
pub struct MozMap<T> {
|
||||
map: HashMap<DOMString, T>,
|
||||
map: IndexMap<DOMString, T>,
|
||||
}
|
||||
|
||||
impl<T> MozMap<T> {
|
||||
/// Create an empty `MozMap`.
|
||||
pub fn new() -> Self {
|
||||
MozMap {
|
||||
map: HashMap::new(),
|
||||
map: IndexMap::new(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<T> Deref for MozMap<T> {
|
||||
type Target = HashMap<DOMString, T>;
|
||||
type Target = IndexMap<DOMString, T>;
|
||||
|
||||
fn deref(&self) -> &HashMap<DOMString, T> {
|
||||
fn deref(&self) -> &IndexMap<DOMString, T> {
|
||||
&self.map
|
||||
}
|
||||
}
|
||||
|
@ -82,7 +82,7 @@ where
|
|||
));
|
||||
}
|
||||
|
||||
let mut map = HashMap::new();
|
||||
let mut map = IndexMap::new();
|
||||
for id in &*ids {
|
||||
rooted!(in(cx) let id = *id);
|
||||
|
||||
|
|
|
@ -61,6 +61,7 @@ use html5ever::{LocalName, Namespace, Prefix, QualName};
|
|||
use http::header::HeaderMap;
|
||||
use hyper::Method;
|
||||
use hyper::StatusCode;
|
||||
use indexmap::IndexMap;
|
||||
use ipc_channel::ipc::{IpcReceiver, IpcSender};
|
||||
use js::glue::{CallObjectTracer, CallValueTracer};
|
||||
use js::jsapi::{GCTraceKindToAscii, Heap, JSObject, JSTracer, TraceKind};
|
||||
|
@ -356,6 +357,21 @@ unsafe impl<K: Ord + JSTraceable, V: JSTraceable> JSTraceable for BTreeMap<K, V>
|
|||
}
|
||||
}
|
||||
|
||||
unsafe impl<K, V, S> JSTraceable for IndexMap<K, V, S>
|
||||
where
|
||||
K: Hash + Eq + JSTraceable,
|
||||
V: JSTraceable,
|
||||
S: BuildHasher,
|
||||
{
|
||||
#[inline]
|
||||
unsafe fn trace(&self, trc: *mut JSTracer) {
|
||||
for (k, v) in &*self {
|
||||
k.trace(trc);
|
||||
v.trace(trc);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
unsafe impl<A: JSTraceable, B: JSTraceable> JSTraceable for (A, B) {
|
||||
#[inline]
|
||||
unsafe fn trace(&self, trc: *mut JSTracer) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue