git.delta.rocks / jrsonnet / refs/commits / 625fbae2cdcf

difftreelog

perf(evaluator) use hashmap for object body

Лач2020-07-01parent: #dcbb761.patch.diff
in: master

4 files changed

modifiedbindings/jsonnet/src/lib.rsdiffbeforeafterboth
8 alloc::Layout,8 alloc::Layout,
9 any::Any,9 any::Any,
10 cell::RefCell,10 cell::RefCell,
11 collections::BTreeMap,11 collections::HashMap,
12 ffi::{CStr, CString},12 ffi::{CStr, CString},
13 fs::File,13 fs::File,
14 io::Read,14 io::Read,
191) {191) {
192 match obj {192 match obj {
193 Val::Obj(old) => {193 Val::Obj(old) => {
194 let mut new = BTreeMap::new();194 let mut new = HashMap::new();
195 new.insert(195 new.insert(
196 CStr::from_ptr(name).to_str().unwrap().into(),196 CStr::from_ptr(name).to_str().unwrap().into(),
197 ObjMember {197 ObjMember {
modifiedcrates/jrsonnet-evaluator/src/evaluate.rsdiffbeforeafterboth
10 Visibility,10 Visibility,
11};11};
12use std::{12use std::{collections::HashMap, rc::Rc};
13 collections::{BTreeMap, HashMap},
14 rc::Rc,
15};
1613
17pub fn evaluate_binding(b: &BindSpec, context_creator: ContextCreator) -> (Rc<str>, LazyBinding) {14pub fn evaluate_binding(b: &BindSpec, context_creator: ContextCreator) -> (Rc<str>, LazyBinding) {
242 new_bindings.fill(bindings);239 new_bindings.fill(bindings);
243 }240 }
244241
245 let mut new_members = BTreeMap::new();242 let mut new_members = HashMap::new();
246 for member in members.iter() {243 for member in members.iter() {
247 match member {244 match member {
248 Member::Field(FieldMember {245 Member::Field(FieldMember {
317 ObjBody::MemberList(members) => evaluate_member_list_object(context, &members)?,314 ObjBody::MemberList(members) => evaluate_member_list_object(context, &members)?,
318 ObjBody::ObjComp(obj) => {315 ObjBody::ObjComp(obj) => {
319 let future_this = FutureObjValue::new();316 let future_this = FutureObjValue::new();
320 let mut new_members = BTreeMap::new();317 let mut new_members = HashMap::new();
321 for (k, v) in evaluate_comp(318 for (k, v) in evaluate_comp(
322 context.clone(),319 context.clone(),
323 &|ctx| {320 &|ctx| {
450 0, obj: [Val::Obj]!!Val::Obj, vec![ValType::Obj];447 0, obj: [Val::Obj]!!Val::Obj, vec![ValType::Obj];
451 1, inc_hidden: [Val::Bool]!!Val::Bool, vec![ValType::Bool];448 1, inc_hidden: [Val::Bool]!!Val::Bool, vec![ValType::Bool];
452 ], {449 ], {
453 Ok(Val::Arr(Rc::new(
454 obj.fields_visibility()450 let mut out = obj.fields_visibility()
455 .into_iter()451 .into_iter()
456 .filter(|(_k, v)| *v || inc_hidden)452 .filter(|(_k, v)| *v || inc_hidden)
457 .map(|(k, _v)| Val::Str(k))453 .map(|(k, _v)|k)
454 .collect::<Vec<_>>();
455 out.sort();
458 .collect(),456 Ok(Val::Arr(Rc::new(out.into_iter().map(Val::Str).collect())))
459 )))
460 }))?457 }))?
461 }458 }
462 // object, field, includeHidden459 // object, field, includeHidden
modifiedcrates/jrsonnet-evaluator/src/obj.rsdiffbeforeafterboth
1use crate::{evaluate_add_op, LazyBinding, Result, Val};1use crate::{evaluate_add_op, LazyBinding, Result, Val};
2use indexmap::IndexMap;2use indexmap::IndexMap;
3use jrsonnet_parser::Visibility;3use jrsonnet_parser::{ExprLocation, Visibility};
4use std::{4use std::{cell::RefCell, collections::HashMap, fmt::Debug, rc::Rc};
5 cell::RefCell,
6 collections::{BTreeMap, HashMap},
7 fmt::Debug,
8 rc::Rc,
9};
105
11#[derive(Debug)]6#[derive(Debug)]
18#[derive(Debug)]13#[derive(Debug)]
19pub struct ObjValueInternals {14pub struct ObjValueInternals {
20 super_obj: Option<ObjValue>,15 super_obj: Option<ObjValue>,
21 this_entries: Rc<BTreeMap<Rc<str>, ObjMember>>,16 this_entries: Rc<HashMap<Rc<str>, ObjMember>>,
22 value_cache: RefCell<HashMap<Rc<str>, Val>>,17 value_cache: RefCell<HashMap<Rc<str>, Val>>,
23}18}
24#[derive(Clone)]19#[derive(Clone)]
44impl ObjValue {39impl ObjValue {
45 pub fn new(40 pub fn new(
46 super_obj: Option<ObjValue>,41 super_obj: Option<ObjValue>,
47 this_entries: Rc<BTreeMap<Rc<str>, ObjMember>>,42 this_entries: Rc<HashMap<Rc<str>, ObjMember>>,
48 ) -> ObjValue {43 ) -> ObjValue {
49 ObjValue(Rc::new(ObjValueInternals {44 ObjValue(Rc::new(ObjValueInternals {
50 super_obj,45 super_obj,
53 }))48 }))
54 }49 }
55 pub fn new_empty() -> ObjValue {50 pub fn new_empty() -> ObjValue {
56 Self::new(None, Rc::new(BTreeMap::new()))51 Self::new(None, Rc::new(HashMap::new()))
57 }52 }
58 pub fn with_super(&self, super_obj: ObjValue) -> ObjValue {53 pub fn with_super(&self, super_obj: ObjValue) -> ObjValue {
59 match &self.0.super_obj {54 match &self.0.super_obj {
modifiedcrates/jrsonnet-evaluator/src/val.rsdiffbeforeafterboth
246 }246 }
247 Val::Obj(obj) => {247 Val::Obj(obj) => {
248 buf.push_str("{\n");248 buf.push_str("{\n");
249 let fields = obj.visible_fields();249 let mut fields = obj.visible_fields();
250 fields.sort();
250 if !fields.is_empty() {251 if !fields.is_empty() {
251 let old_len = cur_padding.len();252 let old_len = cur_padding.len();
252 cur_padding.push_str(padding);253 cur_padding.push_str(padding);