difftreelog
perf Rc file name
in: master
5 files changed
crates/jsonnet-evaluator/build.rsdiffbeforeafterboth15 let parsed = parse(15 let parsed = parse(16 STDLIB_STR,16 STDLIB_STR,17 &ParserSettings {17 &ParserSettings {18 file_name: PathBuf::from("std.jsonnet"),18 file_name: Rc::new(PathBuf::from("std.jsonnet")),19 loc_data: true,19 loc_data: true,20 },20 },21 )21 )crates/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>);
crates/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();
crates/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
},
crates/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()