Did some basic optimizations that made things fast again. Yay!

The basis for the optimizations were some less basic changes made
in Ropey.
This commit is contained in:
Nathan Vegdahl 2018-07-05 04:41:58 -07:00
parent 5ca0f5e406
commit b19997b975
3 changed files with 16 additions and 11 deletions

8
Cargo.lock generated
View File

@ -8,7 +8,7 @@ dependencies = [
"serde_derive 1.0.27 (registry+https://github.com/rust-lang/crates.io-index)", "serde_derive 1.0.27 (registry+https://github.com/rust-lang/crates.io-index)",
"smallvec 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)", "smallvec 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)",
"termion 1.5.1 (registry+https://github.com/rust-lang/crates.io-index)", "termion 1.5.1 (registry+https://github.com/rust-lang/crates.io-index)",
"unicode-segmentation 1.2.0 (registry+https://github.com/rust-lang/crates.io-index)", "unicode-segmentation 1.2.1 (registry+https://github.com/rust-lang/crates.io-index)",
"unicode-width 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)", "unicode-width 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)",
] ]
@ -88,7 +88,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]] [[package]]
name = "ropey" name = "ropey"
version = "0.6.3" version = "0.6.3"
source = "git+https://github.com/cessen/ropey#e9b361b5b45d3e389bbfcb4f75127bec69e0b199" source = "git+https://github.com/cessen/ropey#140e79caa4b8d0215e6f0b70c7269a6715e53498"
dependencies = [ dependencies = [
"smallvec 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)", "smallvec 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)",
] ]
@ -166,7 +166,7 @@ dependencies = [
[[package]] [[package]]
name = "unicode-segmentation" name = "unicode-segmentation"
version = "1.2.0" version = "1.2.1"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]] [[package]]
@ -218,7 +218,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
"checksum synom 0.11.3 (registry+https://github.com/rust-lang/crates.io-index)" = "a393066ed9010ebaed60b9eafa373d4b1baac186dd7e008555b0f702b51945b6" "checksum synom 0.11.3 (registry+https://github.com/rust-lang/crates.io-index)" = "a393066ed9010ebaed60b9eafa373d4b1baac186dd7e008555b0f702b51945b6"
"checksum termion 1.5.1 (registry+https://github.com/rust-lang/crates.io-index)" = "689a3bdfaab439fd92bc87df5c4c78417d3cbe537487274e9b0b2dce76e92096" "checksum termion 1.5.1 (registry+https://github.com/rust-lang/crates.io-index)" = "689a3bdfaab439fd92bc87df5c4c78417d3cbe537487274e9b0b2dce76e92096"
"checksum thread_local 0.3.5 (registry+https://github.com/rust-lang/crates.io-index)" = "279ef31c19ededf577bfd12dfae728040a21f635b06a24cd670ff510edd38963" "checksum thread_local 0.3.5 (registry+https://github.com/rust-lang/crates.io-index)" = "279ef31c19ededf577bfd12dfae728040a21f635b06a24cd670ff510edd38963"
"checksum unicode-segmentation 1.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "a8083c594e02b8ae1654ae26f0ade5158b119bd88ad0e8227a5d8fcd72407946" "checksum unicode-segmentation 1.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "aa6024fc12ddfd1c6dbc14a80fa2324d4568849869b779f6bd37e5e4c03344d1"
"checksum unicode-width 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)" = "bf3a113775714a22dcb774d8ea3655c53a32debae63a063acc00a91cc586245f" "checksum unicode-width 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)" = "bf3a113775714a22dcb774d8ea3655c53a32debae63a063acc00a91cc586245f"
"checksum unicode-xid 0.0.4 (registry+https://github.com/rust-lang/crates.io-index)" = "8c1f860d7d29cf02cb2f3f359fd35991af3d30bac52c57d265a3c461074cb4dc" "checksum unicode-xid 0.0.4 (registry+https://github.com/rust-lang/crates.io-index)" = "8c1f860d7d29cf02cb2f3f359fd35991af3d30bac52c57d265a3c461074cb4dc"
"checksum unreachable 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "382810877fe448991dfc7f0dd6e3ae5d58088fd0ea5e35189655f84e6814fa56" "checksum unreachable 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "382810877fe448991dfc7f0dd6e3ae5d58088fd0ea5e35189655f84e6814fa56"

View File

@ -15,7 +15,7 @@ use utils::{digit_count, RopeGraphemes};
pub mod formatter; pub mod formatter;
mod screen; mod screen;
mod smallstring; pub mod smallstring;
use self::screen::{Color, Screen, Style}; use self::screen::{Color, Screen, Style};

View File

@ -16,9 +16,8 @@ pub fn digit_count(mut n: u32, b: u32) -> u32 {
//============================================================= //=============================================================
pub fn grapheme_width(slice: &RopeSlice) -> usize { pub fn grapheme_width(slice: &RopeSlice) -> usize {
// TODO: use a small stack-allocated buffer to handle the common case use term_ui::smallstring::SmallString;
// without allocation. let s = SmallString::from_rope_slice(slice);
let s = slice.to_string();
return UnicodeWidthStr::width(&s[..]); return UnicodeWidthStr::width(&s[..]);
} }
@ -167,10 +166,16 @@ impl<'a> Iterator for RopeGraphemes<'a> {
} }
} }
if a < self.cur_chunk_start {
let a_char = self.text.byte_to_char(a); let a_char = self.text.byte_to_char(a);
let b_char = self.text.byte_to_char(b); let b_char = self.text.byte_to_char(b);
Some(self.text.slice(a_char..b_char)) Some(self.text.slice(a_char..b_char))
} else {
let a2 = a - self.cur_chunk_start;
let b2 = b - self.cur_chunk_start;
Some(RopeSlice::from_str(&self.cur_chunk[a2..b2]))
}
} }
} }