Skip to content

Commit f3adf8a

Browse files
authored
Remove yet more string allocations (#759)
1 parent 66b27c0 commit f3adf8a

File tree

3 files changed

+11
-11
lines changed

3 files changed

+11
-11
lines changed

librubyfmt/src/format.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1172,16 +1172,16 @@ pub fn format_paren(ps: &mut ParserState, paren: ParenExpr) {
11721172
}
11731173

11741174
pub fn format_dot2(ps: &mut ParserState, dot2: Dot2) {
1175-
format_dot2_or_3(ps, "..".to_string(), dot2.1, dot2.2);
1175+
format_dot2_or_3(ps, "..", dot2.1, dot2.2);
11761176
}
11771177

11781178
pub fn format_dot3(ps: &mut ParserState, dot3: Dot3) {
1179-
format_dot2_or_3(ps, "...".to_string(), dot3.1, dot3.2);
1179+
format_dot2_or_3(ps, "...", dot3.1, dot3.2);
11801180
}
11811181

11821182
pub fn format_dot2_or_3(
11831183
ps: &mut ParserState,
1184-
dots: String,
1184+
dots: &'static str,
11851185
left: Option<Box<Expression>>,
11861186
right: Option<Box<Expression>>,
11871187
) {
@@ -1206,12 +1206,12 @@ pub fn format_dot2_or_3(
12061206
}
12071207
}
12081208

1209-
pub fn percent_symbol_for(tag: String) -> String {
1209+
pub fn percent_symbol_for(tag: String) -> &'static str {
12101210
match tag.as_ref() {
1211-
"qsymbols" => "%i".to_string(),
1212-
"qwords" => "%w".to_string(),
1213-
"symbols" => "%I".to_string(),
1214-
"words" => "%W".to_string(),
1211+
"qsymbols" => "%i",
1212+
"qwords" => "%w",
1213+
"symbols" => "%I",
1214+
"words" => "%W",
12151215
_ => panic!("got invalid percent symbol"),
12161216
}
12171217
}

librubyfmt/src/format_prism.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2164,7 +2164,7 @@ fn format_call_chain_segments<'src>(
21642164
// Attr_write values are formatted after the breakable so they break independently
21652165
if let Some(value) = trailing_attr_write_value {
21662166
ps.emit_space();
2167-
ps.emit_op("=".to_string());
2167+
ps.emit_op("=");
21682168
ps.emit_space();
21692169
ps.with_start_of_line(false, |ps| format_node(ps, value));
21702170
}
@@ -2728,7 +2728,7 @@ fn format_array_node<'src>(ps: &mut ParserState<'src>, array_node: prism::ArrayN
27282728
let orig_delim = opening.and_then(|s| s.chars().nth(2)).unwrap_or('[');
27292729

27302730
if is_word_array {
2731-
ps.emit_ident(opening.unwrap().split_at(2).0.to_string());
2731+
ps.emit_ident(opening.unwrap().split_at(2).0);
27322732
}
27332733

27342734
if array_node.elements().is_empty() {

librubyfmt/src/string_escape.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ pub fn single_to_double_quoted(content: &str, start_delim: &str, end_delim: &str
2727
.replace_all(content, |captures: &fancy_regex::Captures| {
2828
// first capture is the entire match
2929
let val = captures.get(0).unwrap();
30-
let val_str = val.as_str().to_string();
30+
let val_str = val.as_str();
3131
if val_str.ends_with("\"") {
3232
// Ends with a quote, which we transform to `\"`
3333
format!("{}\\\"", &val_str[0..(val_str.len() - 1)])

0 commit comments

Comments
 (0)