From 9348a9a9163cb2bb5b0c5fdaba93b9ec6e7d14b5 Mon Sep 17 00:00:00 2001 From: Nathan Vegdahl Date: Thu, 5 Jul 2018 05:01:57 -0700 Subject: [PATCH] Another small optimization. --- Cargo.lock | 2 +- src/utils.rs | 8 ++++++-- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index ac050e3..167c597 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -88,7 +88,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] name = "ropey" version = "0.6.3" -source = "git+https://github.com/cessen/ropey#140e79caa4b8d0215e6f0b70c7269a6715e53498" +source = "git+https://github.com/cessen/ropey#e6a449e07841da690f369eeb9ef05d55fe102623" dependencies = [ "smallvec 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)", ] diff --git a/src/utils.rs b/src/utils.rs index 624d78d..65cc292 100644 --- a/src/utils.rs +++ b/src/utils.rs @@ -17,8 +17,12 @@ pub fn digit_count(mut n: u32, b: u32) -> u32 { pub fn grapheme_width(slice: &RopeSlice) -> usize { use term_ui::smallstring::SmallString; - let s = SmallString::from_rope_slice(slice); - return UnicodeWidthStr::width(&s[..]); + if let Some(text) = slice.as_str() { + return UnicodeWidthStr::width(text); + } else { + let text = SmallString::from_rope_slice(slice); + return UnicodeWidthStr::width(&text[..]); + } } /// Finds the previous grapheme boundary before the given char position.