Skip to content

Commit a037b58

Browse files
authored
[prism] Avoid allocating Strings by threading 'src lifetime throughout parser state and node types (#745)
* Thread lifetimes through ParserState and associated structs * [prism] Add lifetimes to formatting functions * Remove a bunch of _to_string calls and clones * fmt
1 parent 4d8d108 commit a037b58

File tree

9 files changed

+754
-667
lines changed

9 files changed

+754
-667
lines changed

librubyfmt/src/comment_block.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ impl CommentBlock {
2424
self.comments.push(line);
2525
}
2626

27-
pub fn into_line_tokens(self) -> impl Iterator<Item = ConcreteLineToken> {
27+
pub fn into_line_tokens<'src>(self) -> impl Iterator<Item = ConcreteLineToken<'src>> {
2828
self.comments.into_iter().flat_map(|c| {
2929
[
3030
ConcreteLineToken::Comment { contents: c },

librubyfmt/src/delimiters.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -82,25 +82,25 @@ impl BreakableDelims {
8282
}
8383
}
8484

85-
pub fn single_line_open(&self) -> ConcreteLineToken {
85+
pub fn single_line_open<'src>(&self) -> ConcreteLineToken<'src> {
8686
ConcreteLineToken::Delim {
8787
contents: self.single_line.open,
8888
}
8989
}
9090

91-
pub fn single_line_close(&self) -> ConcreteLineToken {
91+
pub fn single_line_close<'src>(&self) -> ConcreteLineToken<'src> {
9292
ConcreteLineToken::Delim {
9393
contents: self.single_line.close,
9494
}
9595
}
9696

97-
pub fn multi_line_open(&self) -> ConcreteLineToken {
97+
pub fn multi_line_open<'src>(&self) -> ConcreteLineToken<'src> {
9898
ConcreteLineToken::Delim {
9999
contents: self.multi_line.open,
100100
}
101101
}
102102

103-
pub fn multi_line_close(&self) -> ConcreteLineToken {
103+
pub fn multi_line_close<'src>(&self) -> ConcreteLineToken<'src> {
104104
ConcreteLineToken::Delim {
105105
contents: self.multi_line.close,
106106
}

0 commit comments

Comments
 (0)