git.delta.rocks / jrsonnet / refs/commits / 03f24e72fbec

difftreelog

perf(evaluator) deserialize instead of parsing std

Лач2020-06-04parent: #f306bde.patch.diff
in: master

3 files changed

modifiedcrates/jsonnet-evaluator/Cargo.tomldiffbeforeafterboth
66
7# 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.html
8
9[features]
10default = ["serialized-stdlib"]
11serialized-stdlib = ["serde", "bincode"]
812
9[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" }
17
18[dependencies.serde]
19version = "1.0.111"
20optional = true
21
22[dependencies.bincode]
23version = "1.2.1"
24optional = true
25
26[build-dependencies]
27jsonnet-parser = { path = "../jsonnet-parser" }
28jsonnet-stdlib = { path = "../jsonnet-stdlib" }
29serde = "1.0.111"
30bincode = "1.2.1"
1331
addedcrates/jsonnet-evaluator/build.rsdiffbeforeafterboth

no changes

modifiedcrates/jsonnet-evaluator/src/lib.rsdiffbeforeafterboth
41pub struct EvaluationStateInternals {41pub struct EvaluationStateInternals {
42 /// Used for stack-overflows and stacktraces42 /// Used for stack-overflows and stacktraces
43 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 pretty
45 /// printing stacktraces
45 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}
8485
85 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.0
95 .files
96 .borrow_mut()
97 .insert(name, FileData(code, parsed, None));
98
99 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_map
134 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();