Some nice performance improvements with a simple optimization.

We're now very close to being back to the performance levels
we were at before the new Ropey without built-in grapheme
support.
This commit is contained in:
Nathan Vegdahl 2018-07-05 18:43:17 -07:00
parent 9348a9a916
commit f8a38111d4
2 changed files with 29 additions and 23 deletions

2
Cargo.lock generated
View File

@ -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#e6a449e07841da690f369eeb9ef05d55fe102623"
source = "git+https://github.com/cessen/ropey#41fb82d82279e8f20c2be680f661ee2f6c0e1c78"
dependencies = [
"smallvec 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)",
]

View File

@ -54,6 +54,9 @@ pub fn rope_slice_is_whitespace(text: &RopeSlice) -> bool {
// For better categorization these should be split up into groups
// based on e.g. breaking vs non-breaking spaces, among other things.
if let Some(text) = text.as_str() {
is_whitespace(text)
} else {
text == "\u{0020}" // SPACE
|| text == "\u{0009}" // CHARACTER TABULATION
|| text == "\u{00A0}" // NO-BREAK SPACE
@ -76,6 +79,7 @@ pub fn rope_slice_is_whitespace(text: &RopeSlice) -> bool {
|| text == "\u{3000}" // IDEOGRAPHIC SPACE
|| text == "\u{FEFF}" // ZERO WIDTH NO-BREAK SPACE
}
}
pub fn line_ending_count(text: &str) -> usize {
let mut count = 0;
@ -320,7 +324,9 @@ pub fn str_to_line_ending(g: &str) -> LineEnding {
}
pub fn rope_slice_to_line_ending(g: &RopeSlice) -> LineEnding {
if g == "\u{000D}\u{000A}" {
if let Some(text) = g.as_str() {
str_to_line_ending(text)
} else if g == "\u{000D}\u{000A}" {
LineEnding::CRLF
} else if g == "\u{000A}" {
LineEnding::LF