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.rsdiffbeforeafterboth38}38}393940#[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>);4444crates/jsonnet-evaluator/src/lib.rsdiffbeforeafterboth117 parse(117 parse(118 &code,118 &code,119 &ParserSettings {119 &ParserSettings {120 file_name: name,120 file_name: Rc::new(name),121 loc_data: true,121 loc_data: true,122 },122 },123 )?,123 )?,198 let parsed = parse(198 let parsed = parse(199 &code,199 &code,200 &ParserSettings {200 &ParserSettings {201 file_name: PathBuf::from("raw.jsonnet"),201 file_name: Rc::new(PathBuf::from("raw.jsonnet")),202 loc_data: true,202 loc_data: true,203 },203 },204 )204 )320 let state = EvaluationState::default();320 let state = EvaluationState::default();321 state321 state322 .push(322 .push(323 Rc::new(ExprLocation(PathBuf::from("test1.jsonnet"), 10, 20)),323 ExprLocation(Rc::new(PathBuf::from("test1.jsonnet")), 10, 20),324 "outer".to_owned(),324 "outer".to_owned(),325 || {325 || {326 state.push(326 state.push(327 Rc::new(ExprLocation(PathBuf::from("test2.jsonnet"), 30, 40)),327 ExprLocation(Rc::new(PathBuf::from("test2.jsonnet")), 30, 40),328 "inner".to_owned(),328 "inner".to_owned(),329 || {329 || {330 state.print_stack_trace();330 state.print_stack_trace();crates/jsonnet-parser/src/expr.rsdiffbeforeafterboth207207208/// file, begin offset, end offset208/// file, begin offset, end offset209#[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)216216217/// 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 None240 },236 },crates/jsonnet-parser/src/lib.rsdiffbeforeafterboth111112pub struct ParserSettings {12pub struct ParserSettings {13 pub loc_data: bool,13 pub loc_data: bool,14 pub file_name: PathBuf,14 pub file_name: Rc<PathBuf>,15}15}161617parser! {17parser! {289 } end:position!() {289 } end:position!() {290 let LocExpr(e, _) = a;290 let LocExpr(e, _) = a;291 LocExpr(e, if s.loc_data {291 LocExpr(e, if s.loc_data {292 Some(Rc::new(ExprLocation(s.file_name.to_owned(), start, end)))292 Some(ExprLocation(s.file_name.clone(), start, end))293 } else {293 } else {294 None294 None295 })295 })317 use super::{expr::*, parse};317 use super::{expr::*, parse};318 use crate::ParserSettings;318 use crate::ParserSettings;319 use std::path::PathBuf;319 use std::path::PathBuf;320 use std::rc::Rc;320321321 macro_rules! parse {322 macro_rules! parse {322 ($s:expr) => {323 ($s:expr) => {323 parse(324 parse(324 $s,325 $s,325 &ParserSettings {326 &ParserSettings {326 loc_data: false,327 loc_data: false,327 file_name: PathBuf::from("/test.jsonnet"),328 file_name: Rc::new(PathBuf::from("/test.jsonnet")),328 },329 },329 )330 )330 .unwrap()331 .unwrap()