]> git.lizzy.rs Git - rust.git/commitdiff
Rollup merge of #48167 - Mark-Simulacrum:remove-allocation-codemap, r=estebank
authorkennytm <kennytm@gmail.com>
Wed, 14 Feb 2018 08:14:47 +0000 (16:14 +0800)
committerkennytm <kennytm@gmail.com>
Wed, 14 Feb 2018 10:25:27 +0000 (18:25 +0800)
Remove allocation from width of character function.

Locally this seems to eliminate the problem or at least resolve most of the
issue.

Fixes #48153.

r? @estebank

src/libsyntax/codemap.rs

index 3601b9ba8a8c1cdbf8b5669f1fd42e5f0b17cf17..ff6f32fc3be0bb7808319ccc756159e1abcfee69 100644 (file)
@@ -690,14 +690,16 @@ fn find_width_of_character_at_span(&self, sp: Span, forwards: bool) -> u32 {
             return 1;
         }
 
+        let src = local_begin.fm.external_src.borrow();
+
         // We need to extend the snippet to the end of the src rather than to end_index so when
         // searching forwards for boundaries we've got somewhere to search.
         let snippet = if let Some(ref src) = local_begin.fm.src {
             let len = src.len();
-            (&src[start_index..len]).to_string()
-        } else if let Some(src) = local_begin.fm.external_src.borrow().get_source() {
+            (&src[start_index..len])
+        } else if let Some(src) = src.get_source() {
             let len = src.len();
-            (&src[start_index..len]).to_string()
+            (&src[start_index..len])
         } else {
             return 1;
         };