From 7e74af32268f9b0783ca94107b0b10d52e4ebe5e Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Tue, 28 Aug 2018 14:06:30 +0300 Subject: Avoid materializing strings --- crates/libeditor/src/code_actions.rs | 4 ++-- crates/libeditor/src/typing.rs | 17 ++++++++--------- 2 files changed, 10 insertions(+), 11 deletions(-) (limited to 'crates/libeditor') diff --git a/crates/libeditor/src/code_actions.rs b/crates/libeditor/src/code_actions.rs index e6ba83d2e..cd5146d87 100644 --- a/crates/libeditor/src/code_actions.rs +++ b/crates/libeditor/src/code_actions.rs @@ -29,8 +29,8 @@ pub fn flip_comma<'a>(file: &'a File, offset: TextUnit) -> Option ActionResult { let range = if range.is_empty() { - let text = file.syntax().text(); - let text = &text[TextRange::from_to(range.start(), TextUnit::of_str(&text))]; - let pos = text.bytes().take_while(|&b| b != b'\n').count(); - if pos == text.len() { - return ActionResult { + let syntax = file.syntax(); + let text = syntax.text().slice(range.start()..); + let pos = match text.find('\n') { + None => return ActionResult { edit: EditBuilder::new().finish(), cursor_position: None - }; - } - let pos: TextUnit = (pos as u32).into(); + }, + Some(pos) => pos + }; TextRange::offset_len( range.start() + pos, TextUnit::of_char('\n'), @@ -129,7 +128,7 @@ fn join_lambda_body( let expr = single_expr(block)?; edit.replace( block_expr.syntax().range(), - expr.syntax().text(), + expr.syntax().text().to_string(), ); Some(()) } -- cgit v1.2.3