difftreelog
refactor drop LayeredHashMap key generic
in: master
2 files changed
crates/jrsonnet-evaluator/src/ctx.rsdiffbeforeafterboth19 dollar: Option<ObjValue>,19 dollar: Option<ObjValue>,20 this: Option<ObjValue>,20 this: Option<ObjValue>,21 super_obj: Option<ObjValue>,21 super_obj: Option<ObjValue>,22 bindings: LayeredHashMap<IStr, LazyVal>,22 bindings: LayeredHashMap<LazyVal>,23}23}24impl Debug for ContextInternals {24impl Debug for ContextInternals {25 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {25 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {crates/jrsonnet-evaluator/src/map.rsdiffbeforeafterboth--- a/crates/jrsonnet-evaluator/src/map.rs
+++ b/crates/jrsonnet-evaluator/src/map.rs
@@ -1,17 +1,18 @@
+use jrsonnet_interner::IStr;
use rustc_hash::FxHashMap;
-use std::{borrow::Borrow, hash::Hash, rc::Rc};
+use std::rc::Rc;
#[derive(Default, Debug)]
-struct LayeredHashMapInternals<K: Hash, V> {
- parent: Option<LayeredHashMap<K, V>>,
- current: FxHashMap<K, V>,
+struct LayeredHashMapInternals<V> {
+ parent: Option<LayeredHashMap<V>>,
+ current: FxHashMap<IStr, V>,
}
#[derive(Debug)]
-pub struct LayeredHashMap<K: Hash, V>(Rc<LayeredHashMapInternals<K, V>>);
+pub struct LayeredHashMap<V>(Rc<LayeredHashMapInternals<V>>);
-impl<K: Hash + Eq, V> LayeredHashMap<K, V> {
- pub fn extend(self, new_layer: FxHashMap<K, V>) -> Self {
+impl<V> LayeredHashMap<V> {
+ pub fn extend(self, new_layer: FxHashMap<IStr, V>) -> Self {
match Rc::try_unwrap(self.0) {
Ok(mut map) => {
map.current.extend(new_layer);
@@ -24,11 +25,7 @@
}
}
- pub fn get<Q: ?Sized>(&self, key: &Q) -> Option<&V>
- where
- K: Borrow<Q>,
- Q: Hash + Eq,
- {
+ pub fn get(&self, key: &IStr) -> Option<&V> {
(self.0)
.current
.get(key)
@@ -36,13 +33,13 @@
}
}
-impl<K: Hash, V> Clone for LayeredHashMap<K, V> {
+impl<V> Clone for LayeredHashMap<V> {
fn clone(&self) -> Self {
Self(self.0.clone())
}
}
-impl<K: Hash + Eq, V> Default for LayeredHashMap<K, V> {
+impl<V> Default for LayeredHashMap<V> {
fn default() -> Self {
Self(Rc::new(LayeredHashMapInternals {
parent: None,