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
38}38}
3939
40#[derive(Clone, Debug)]40#[derive(Clone, Debug)]
41pub struct StackTraceElement(pub Rc<ExprLocation>, pub String);41pub struct StackTraceElement(pub ExprLocation, pub String);
42#[derive(Debug, Clone)]42#[derive(Debug, Clone)]
43pub struct StackTrace(pub Vec<StackTraceElement>);43pub struct StackTrace(pub Vec<StackTraceElement>);
4444
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
--- a/crates/jsonnet-parser/src/expr.rs
+++ b/crates/jsonnet-parser/src/expr.rs
@@ -207,7 +207,7 @@
 
 /// file, begin offset, end offset
 #[derive(Clone, PartialEq, Serialize, Deserialize)]
-pub struct ExprLocation(pub PathBuf, pub usize, pub usize);
+pub struct ExprLocation(pub Rc<PathBuf>, pub usize, pub usize);
 impl Debug for ExprLocation {
 	fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
 		write!(f, "{:?}:{:?}-{:?}", self.0, self.1, self.2)
@@ -216,7 +216,7 @@
 
 /// Holds AST expression and its location in source file+
 #[derive(Clone, PartialEq, Serialize, Deserialize)]
-pub struct LocExpr(pub Rc<Expr>, pub Option<Rc<ExprLocation>>);
+pub struct LocExpr(pub Rc<Expr>, pub Option<ExprLocation>);
 impl Debug for LocExpr {
 	fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
 		write!(f, "{:?} from {:?}", self.0, self.1)
@@ -230,11 +230,7 @@
 		LocExpr(
 			std::rc::Rc::new($expr),
 			if $need_loc {
-				Some(std::rc::Rc::new(ExprLocation(
-					$name.to_owned(),
-					$start,
-					$end,
-				)))
+				Some(ExprLocation($name, $start, $end))
 			} else {
 				None
 				},
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()