git.delta.rocks / jrsonnet / refs/commits / c214d990b22e

difftreelog

refactor drop LayeredHashMap key generic

Yaroslav Bolyukin2021-01-12parent: #970fbe7.patch.diff
in: master

2 files changed

modifiedcrates/jrsonnet-evaluator/src/ctx.rsdiffbeforeafterboth
--- a/crates/jrsonnet-evaluator/src/ctx.rs
+++ b/crates/jrsonnet-evaluator/src/ctx.rs
@@ -19,7 +19,7 @@
 	dollar: Option<ObjValue>,
 	this: Option<ObjValue>,
 	super_obj: Option<ObjValue>,
-	bindings: LayeredHashMap<IStr, LazyVal>,
+	bindings: LayeredHashMap<LazyVal>,
 }
 impl Debug for ContextInternals {
 	fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
modifiedcrates/jrsonnet-evaluator/src/map.rsdiffbeforeafterboth
1use jrsonnet_interner::IStr;
1use rustc_hash::FxHashMap;2use rustc_hash::FxHashMap;
2use std::{borrow::Borrow, hash::Hash, rc::Rc};3use std::rc::Rc;
34
4#[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}
910
10#[derive(Debug)]11#[derive(Debug)]
11pub struct LayeredHashMap<K: Hash, V>(Rc<LayeredHashMapInternals<K, V>>);12pub struct LayeredHashMap<V>(Rc<LayeredHashMapInternals<V>>);
1213
13impl<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 }
2627
27 pub fn get<Q: ?Sized>(&self, key: &Q) -> Option<&V>28 pub fn get(&self, key: &IStr) -> Option<&V> {
28 where
29 K: Borrow<Q>,
30 Q: Hash + Eq,
31 {
32 (self.0)29 (self.0)
33 .current30 .current
36 }33 }
37}34}
3835
39impl<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}
4441
45impl<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,