From c214d990b22e56a56575f1209dfca970086be312 Mon Sep 17 00:00:00 2001 From: Yaroslav Bolyukin Date: Tue, 12 Jan 2021 03:57:05 +0000 Subject: [PATCH] refactor: drop LayeredHashMap key generic --- --- a/crates/jrsonnet-evaluator/src/ctx.rs +++ b/crates/jrsonnet-evaluator/src/ctx.rs @@ -19,7 +19,7 @@ dollar: Option, this: Option, super_obj: Option, - bindings: LayeredHashMap, + bindings: LayeredHashMap, } impl Debug for ContextInternals { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { --- 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 { - parent: Option>, - current: FxHashMap, +struct LayeredHashMapInternals { + parent: Option>, + current: FxHashMap, } #[derive(Debug)] -pub struct LayeredHashMap(Rc>); +pub struct LayeredHashMap(Rc>); -impl LayeredHashMap { - pub fn extend(self, new_layer: FxHashMap) -> Self { +impl LayeredHashMap { + pub fn extend(self, new_layer: FxHashMap) -> Self { match Rc::try_unwrap(self.0) { Ok(mut map) => { map.current.extend(new_layer); @@ -24,11 +25,7 @@ } } - pub fn get(&self, key: &Q) -> Option<&V> - where - K: Borrow, - Q: Hash + Eq, - { + pub fn get(&self, key: &IStr) -> Option<&V> { (self.0) .current .get(key) @@ -36,13 +33,13 @@ } } -impl Clone for LayeredHashMap { +impl Clone for LayeredHashMap { fn clone(&self) -> Self { Self(self.0.clone()) } } -impl Default for LayeredHashMap { +impl Default for LayeredHashMap { fn default() -> Self { Self(Rc::new(LayeredHashMapInternals { parent: None, -- gitstuff