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.rsdiffbeforeafterboth1use jrsonnet_interner::IStr;1use rustc_hash::FxHashMap;2use rustc_hash::FxHashMap;2use std::{borrow::Borrow, hash::Hash, rc::Rc};3use std::rc::Rc;344#[derive(Default, Debug)]5#[derive(Default, Debug)]5struct LayeredHashMapInternals<K: Hash, V> {6struct LayeredHashMapInternals<V> {6 parent: Option<LayeredHashMap<K, V>>,7 parent: Option<LayeredHashMap<V>>,7 current: FxHashMap<K, V>,8 current: FxHashMap<IStr, V>,8}9}91010#[derive(Debug)]11#[derive(Debug)]11pub struct LayeredHashMap<K: Hash, V>(Rc<LayeredHashMapInternals<K, V>>);12pub struct LayeredHashMap<V>(Rc<LayeredHashMapInternals<V>>);121313impl<K: Hash + Eq, V> LayeredHashMap<K, V> {14impl<V> LayeredHashMap<V> {14 pub fn extend(self, new_layer: FxHashMap<K, V>) -> Self {15 pub fn extend(self, new_layer: FxHashMap<IStr, V>) -> Self {15 match Rc::try_unwrap(self.0) {16 match Rc::try_unwrap(self.0) {16 Ok(mut map) => {17 Ok(mut map) => {17 map.current.extend(new_layer);18 map.current.extend(new_layer);24 }25 }25 }26 }262727 pub fn get<Q: ?Sized>(&self, key: &Q) -> Option<&V>28 pub fn get(&self, key: &IStr) -> Option<&V> {28 where29 K: Borrow<Q>,30 Q: Hash + Eq,31 {32 (self.0)29 (self.0)33 .current30 .current36 }33 }37}34}383539impl<K: Hash, V> Clone for LayeredHashMap<K, V> {36impl<V> Clone for LayeredHashMap<V> {40 fn clone(&self) -> Self {37 fn clone(&self) -> Self {41 Self(self.0.clone())38 Self(self.0.clone())42 }39 }43}40}444145impl<K: Hash + Eq, V> Default for LayeredHashMap<K, V> {42impl<V> Default for LayeredHashMap<V> {46 fn default() -> Self {43 fn default() -> Self {47 Self(Rc::new(LayeredHashMapInternals {44 Self(Rc::new(LayeredHashMapInternals {48 parent: None,45 parent: None,