temp
This commit is contained in:
+32
-19
@@ -435,65 +435,78 @@ impl fmt::Debug for NixString {
|
||||
#[derive(Collect, Debug, Default)]
|
||||
#[collect(no_drop)]
|
||||
pub(crate) struct AttrSet<'gc> {
|
||||
entries: SmallVec<[(StringId, Value<'gc>); 4]>,
|
||||
pub(crate) entries: RefLock<SmallVec<[(StringId, Value<'gc>); 4]>>,
|
||||
}
|
||||
|
||||
impl<'gc> Deref for AttrSet<'gc> {
|
||||
type Target = [(StringId, Value<'gc>)];
|
||||
fn deref(&self) -> &Self::Target {
|
||||
&self.entries
|
||||
impl<'gc> Unlock for AttrSet<'gc> {
|
||||
type Unlocked = RefCell<SmallVec<[(StringId, Value<'gc>); 4]>>;
|
||||
unsafe fn unlock_unchecked(&self) -> &Self::Unlocked {
|
||||
unsafe { self.entries.unlock_unchecked() }
|
||||
}
|
||||
}
|
||||
|
||||
impl<'gc> AttrSet<'gc> {
|
||||
pub(crate) fn from_sorted_unchecked(entries: SmallVec<[(StringId, Value<'gc>); 4]>) -> Self {
|
||||
debug_assert!(entries.is_sorted_by_key(|(key, _)| *key));
|
||||
Self { entries }
|
||||
Self {
|
||||
entries: RefLock::new(entries),
|
||||
}
|
||||
}
|
||||
|
||||
pub(crate) fn lookup(&self, key: StringId) -> Option<Value<'gc>> {
|
||||
self.entries
|
||||
let entries = self.entries.borrow();
|
||||
entries
|
||||
.binary_search_by_key(&key, |(k, _)| *k)
|
||||
.ok()
|
||||
.map(|i| self.entries[i].1)
|
||||
.map(|i| entries[i].1)
|
||||
}
|
||||
|
||||
pub(crate) fn has(&self, key: StringId) -> bool {
|
||||
self.entries.binary_search_by_key(&key, |(k, _)| *k).is_ok()
|
||||
self.entries
|
||||
.borrow()
|
||||
.binary_search_by_key(&key, |(k, _)| *k)
|
||||
.is_ok()
|
||||
}
|
||||
|
||||
pub(crate) fn merge(&self, other: &Self, mc: &Mutation<'gc>) -> Gc<'gc, Self> {
|
||||
use std::cmp::Ordering::*;
|
||||
|
||||
debug_assert!(self.entries.is_sorted_by_key(|(key, _)| *key));
|
||||
debug_assert!(other.entries.is_sorted_by_key(|(key, _)| *key));
|
||||
let self_entries = self.entries.borrow();
|
||||
let other_entries = other.entries.borrow();
|
||||
debug_assert!(self_entries.is_sorted_by_key(|(key, _)| *key));
|
||||
debug_assert!(other_entries.is_sorted_by_key(|(key, _)| *key));
|
||||
|
||||
let mut entries = SmallVec::new();
|
||||
let mut i = 0;
|
||||
let mut j = 0;
|
||||
while i < self.entries.len() && j < other.entries.len() {
|
||||
match self.entries[i].0.cmp(&other.entries[j].0) {
|
||||
while i < self_entries.len() && j < other_entries.len() {
|
||||
match self_entries[i].0.cmp(&other_entries[j].0) {
|
||||
Less => {
|
||||
entries.push(self.entries[i]);
|
||||
entries.push(self_entries[i]);
|
||||
i += 1;
|
||||
}
|
||||
Greater => {
|
||||
entries.push(other.entries[j]);
|
||||
entries.push(other_entries[j]);
|
||||
j += 1;
|
||||
}
|
||||
Equal => {
|
||||
entries.push(other.entries[j]);
|
||||
entries.push(other_entries[j]);
|
||||
i += 1;
|
||||
j += 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
entries.extend(other.entries[j..].iter().cloned());
|
||||
entries.extend(self.entries[i..].iter().cloned());
|
||||
entries.extend(other_entries[j..].iter().cloned());
|
||||
entries.extend(self_entries[i..].iter().cloned());
|
||||
|
||||
debug_assert!(entries.is_sorted_by_key(|(key, _)| *key));
|
||||
|
||||
Gc::new(mc, AttrSet { entries })
|
||||
Gc::new(
|
||||
mc,
|
||||
AttrSet {
|
||||
entries: RefLock::new(entries),
|
||||
},
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user