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

difftreelog

perf Rc file name

Лач2020-06-26parent: #91108e4.patch.diff
in: master

5 files changed

modifiedcrates/jsonnet-evaluator/build.rsdiffbeforeafterboth
--- a/crates/jsonnet-evaluator/build.rs
+++ b/crates/jsonnet-evaluator/build.rs
@@ -15,7 +15,7 @@
 	let parsed = parse(
 		STDLIB_STR,
 		&ParserSettings {
-			file_name: PathBuf::from("std.jsonnet"),
+			file_name: Rc::new(PathBuf::from("std.jsonnet")),
 			loc_data: true,
 		},
 	)
modifiedcrates/jsonnet-evaluator/src/error.rsdiffbeforeafterboth
--- a/crates/jsonnet-evaluator/src/error.rs
+++ b/crates/jsonnet-evaluator/src/error.rs
@@ -38,7 +38,7 @@
 }
 
 #[derive(Clone, Debug)]
-pub struct StackTraceElement(pub Rc<ExprLocation>, pub String);
+pub struct StackTraceElement(pub ExprLocation, pub String);
 #[derive(Debug, Clone)]
 pub struct StackTrace(pub Vec<StackTraceElement>);
 
modifiedcrates/jsonnet-evaluator/src/lib.rsdiffbeforeafterboth
--- a/crates/jsonnet-evaluator/src/lib.rs
+++ b/crates/jsonnet-evaluator/src/lib.rs
@@ -117,7 +117,7 @@
 				parse(
 					&code,
 					&ParserSettings {
-						file_name: name,
+						file_name: Rc::new(name),
 						loc_data: true,
 					},
 				)?,
@@ -198,7 +198,7 @@
 		let parsed = parse(
 			&code,
 			&ParserSettings {
-				file_name: PathBuf::from("raw.jsonnet"),
+				file_name: Rc::new(PathBuf::from("raw.jsonnet")),
 				loc_data: true,
 			},
 		)
@@ -320,11 +320,11 @@
 		let state = EvaluationState::default();
 		state
 			.push(
-				Rc::new(ExprLocation(PathBuf::from("test1.jsonnet"), 10, 20)),
+				ExprLocation(Rc::new(PathBuf::from("test1.jsonnet")), 10, 20),
 				"outer".to_owned(),
 				|| {
 					state.push(
-						Rc::new(ExprLocation(PathBuf::from("test2.jsonnet"), 30, 40)),
+						ExprLocation(Rc::new(PathBuf::from("test2.jsonnet")), 30, 40),
 						"inner".to_owned(),
 						|| {
 							state.print_stack_trace();
modifiedcrates/jsonnet-parser/src/expr.rsdiffbeforeafterboth
207207
208/// file, begin offset, end offset208/// file, begin offset, end offset
209#[derive(Clone, PartialEq, Serialize, Deserialize)]209#[derive(Clone, PartialEq, Serialize, Deserialize)]
210pub struct ExprLocation(pub PathBuf, pub usize, pub usize);210pub struct ExprLocation(pub Rc<PathBuf>, pub usize, pub usize);
211impl Debug for ExprLocation {211impl Debug for ExprLocation {
212 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {212 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
213 write!(f, "{:?}:{:?}-{:?}", self.0, self.1, self.2)213 write!(f, "{:?}:{:?}-{:?}", self.0, self.1, self.2)
216216
217/// Holds AST expression and its location in source file+217/// Holds AST expression and its location in source file+
218#[derive(Clone, PartialEq, Serialize, Deserialize)]218#[derive(Clone, PartialEq, Serialize, Deserialize)]
219pub struct LocExpr(pub Rc<Expr>, pub Option<Rc<ExprLocation>>);219pub struct LocExpr(pub Rc<Expr>, pub Option<ExprLocation>);
220impl Debug for LocExpr {220impl Debug for LocExpr {
221 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {221 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
222 write!(f, "{:?} from {:?}", self.0, self.1)222 write!(f, "{:?} from {:?}", self.0, self.1)
230 LocExpr(230 LocExpr(
231 std::rc::Rc::new($expr),231 std::rc::Rc::new($expr),
232 if $need_loc {232 if $need_loc {
233 Some(std::rc::Rc::new(ExprLocation(233 Some(ExprLocation($name, $start, $end))
234 $name.to_owned(),
235 $start,
236 $end,
237 )))
238 } else {234 } else {
239 None235 None
240 },236 },
modifiedcrates/jsonnet-parser/src/lib.rsdiffbeforeafterboth
--- a/crates/jsonnet-parser/src/lib.rs
+++ b/crates/jsonnet-parser/src/lib.rs
@@ -11,7 +11,7 @@
 
 pub struct ParserSettings {
 	pub loc_data: bool,
-	pub file_name: PathBuf,
+	pub file_name: Rc<PathBuf>,
 }
 
 parser! {
@@ -289,7 +289,7 @@
 			} end:position!() {
 				let LocExpr(e, _) = a;
 				LocExpr(e, if s.loc_data {
-					Some(Rc::new(ExprLocation(s.file_name.to_owned(), start, end)))
+					Some(ExprLocation(s.file_name.clone(), start, end))
 				} else {
 					None
 				})
@@ -317,6 +317,7 @@
 	use super::{expr::*, parse};
 	use crate::ParserSettings;
 	use std::path::PathBuf;
+	use std::rc::Rc;
 
 	macro_rules! parse {
 		($s:expr) => {
@@ -324,7 +325,7 @@
 				$s,
 				&ParserSettings {
 					loc_data: false,
-					file_name: PathBuf::from("/test.jsonnet"),
+					file_name: Rc::new(PathBuf::from("/test.jsonnet")),
 					},
 				)
 			.unwrap()