difftreelog
perf(evaluator) deserialize instead of parsing std
in: master
3 files changed
crates/jsonnet-evaluator/Cargo.tomldiffbeforeafterboth667# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html7# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html89[features]10default = ["serialized-stdlib"]11serialized-stdlib = ["serde", "bincode"]8129[dependencies]13[dependencies]10jsonnet-parser = { path = "../jsonnet-parser" }14jsonnet-parser = { path = "../jsonnet-parser" }11closure = "0.3.0"15closure = "0.3.0"12jsonnet-stdlib = { version = "0.1.0", path = "../jsonnet-stdlib" }16jsonnet-stdlib = { path = "../jsonnet-stdlib" }1718[dependencies.serde]19version = "1.0.111"20optional = true2122[dependencies.bincode]23version = "1.2.1"24optional = true2526[build-dependencies]27jsonnet-parser = { path = "../jsonnet-parser" }28jsonnet-stdlib = { path = "../jsonnet-stdlib" }29serde = "1.0.111"30bincode = "1.2.1"1331crates/jsonnet-evaluator/build.rsdiffbeforeafterbothno changes
crates/jsonnet-evaluator/src/lib.rsdiffbeforeafterboth41pub struct EvaluationStateInternals {41pub struct EvaluationStateInternals {42 /// Used for stack-overflows and stacktraces42 /// Used for stack-overflows and stacktraces43 stack: RefCell<Vec<StackTraceElement>>,43 stack: RefCell<Vec<StackTraceElement>>,44 /// Contains file source codes and evaluated results for imports and pretty printing stacktraces44 /// Contains file source codes and evaluated results for imports and pretty45 /// printing stacktraces45 files: RefCell<HashMap<String, FileData>>,46 files: RefCell<HashMap<String, FileData>>,46 globals: RefCell<HashMap<String, Val>>,47 globals: RefCell<HashMap<String, Val>>,47}48}848585 Ok(())86 Ok(())86 }87 }88 pub fn add_parsed_file(89 &self,90 name: String,91 code: String,92 parsed: LocExpr,93 ) -> std::result::Result<(), Box<dyn std::error::Error>> {94 self.095 .files96 .borrow_mut()97 .insert(name, FileData(code, parsed, None));9899 Ok(())100 }87 pub fn get_source(&self, name: &str) -> String {101 pub fn get_source(&self, name: &str) -> String {88 let ro_map = self.0.files.borrow();102 let ro_map = self.0.files.borrow();89 let value = ro_map103 let value = ro_map134 pub fn add_stdlib(&self) {148 pub fn add_stdlib(&self) {135 self.begin_state();149 self.begin_state();136 use jsonnet_stdlib::STDLIB_STR;150 use jsonnet_stdlib::STDLIB_STR;151 if cfg!(feature = "serialized-stdlib") {152 self.add_parsed_file(153 "std.jsonnet".to_owned(),154 STDLIB_STR.to_owned(),155 bincode::deserialize(include_bytes!(concat!(env!("OUT_DIR"), "/stdlib.bincode"))).expect("deserialize stdlib"),156 ).unwrap();157 } else {137 self.add_file("std.jsonnet".to_owned(), STDLIB_STR.to_owned())158 self.add_file("std.jsonnet".to_owned(), STDLIB_STR.to_owned())138 .unwrap();159 .unwrap();160 }139 let val = self.evaluate_file("std.jsonnet").unwrap();161 let val = self.evaluate_file("std.jsonnet").unwrap();140 self.0.globals.borrow_mut().insert("std".to_owned(), val);162 self.0.globals.borrow_mut().insert("std".to_owned(), val);141 self.end_state();163 self.end_state();