diff options
author | Aleksey Kladov <[email protected]> | 2018-08-28 12:06:30 +0100 |
---|---|---|
committer | Aleksey Kladov <[email protected]> | 2018-08-28 12:06:30 +0100 |
commit | 7e74af32268f9b0783ca94107b0b10d52e4ebe5e (patch) | |
tree | 179d818c695a27ceee3f8193e219234854190f9a /crates/libeditor/src/typing.rs | |
parent | 363f466627db373fab23d1df94b7382223b8675a (diff) |
Avoid materializing strings
Diffstat (limited to 'crates/libeditor/src/typing.rs')
-rw-r--r-- | crates/libeditor/src/typing.rs | 17 |
1 files changed, 8 insertions, 9 deletions
diff --git a/crates/libeditor/src/typing.rs b/crates/libeditor/src/typing.rs index 2cff96b34..3a3776c26 100644 --- a/crates/libeditor/src/typing.rs +++ b/crates/libeditor/src/typing.rs | |||
@@ -15,16 +15,15 @@ use {ActionResult, EditBuilder, find_node_at_offset}; | |||
15 | 15 | ||
16 | pub fn join_lines(file: &File, range: TextRange) -> ActionResult { | 16 | pub fn join_lines(file: &File, range: TextRange) -> ActionResult { |
17 | let range = if range.is_empty() { | 17 | let range = if range.is_empty() { |
18 | let text = file.syntax().text(); | 18 | let syntax = file.syntax(); |
19 | let text = &text[TextRange::from_to(range.start(), TextUnit::of_str(&text))]; | 19 | let text = syntax.text().slice(range.start()..); |
20 | let pos = text.bytes().take_while(|&b| b != b'\n').count(); | 20 | let pos = match text.find('\n') { |
21 | if pos == text.len() { | 21 | None => return ActionResult { |
22 | return ActionResult { | ||
23 | edit: EditBuilder::new().finish(), | 22 | edit: EditBuilder::new().finish(), |
24 | cursor_position: None | 23 | cursor_position: None |
25 | }; | 24 | }, |
26 | } | 25 | Some(pos) => pos |
27 | let pos: TextUnit = (pos as u32).into(); | 26 | }; |
28 | TextRange::offset_len( | 27 | TextRange::offset_len( |
29 | range.start() + pos, | 28 | range.start() + pos, |
30 | TextUnit::of_char('\n'), | 29 | TextUnit::of_char('\n'), |
@@ -129,7 +128,7 @@ fn join_lambda_body( | |||
129 | let expr = single_expr(block)?; | 128 | let expr = single_expr(block)?; |
130 | edit.replace( | 129 | edit.replace( |
131 | block_expr.syntax().range(), | 130 | block_expr.syntax().range(), |
132 | expr.syntax().text(), | 131 | expr.syntax().text().to_string(), |
133 | ); | 132 | ); |
134 | Some(()) | 133 | Some(()) |
135 | } | 134 | } |