File tree 1 file changed +23
-5
lines changed 1 file changed +23
-5
lines changed Original file line number Diff line number Diff line change @@ -284,12 +284,30 @@ impl GraphemeCursor {
284
284
285
285
fn grapheme_category ( & mut self , ch : char ) -> GraphemeCat {
286
286
use tables:: grapheme as gr;
287
- // If this char isn't within the cached range, update the cache to the
288
- // range that includes it.
289
- if ( ch as u32 ) < self . grapheme_cat_cache . 0 || ( ch as u32 ) > self . grapheme_cat_cache . 1 {
290
- self . grapheme_cat_cache = gr:: grapheme_category ( ch) ;
287
+ use tables:: grapheme:: GraphemeCat :: * ;
288
+
289
+ if ch <= '\u{7e}' {
290
+ // Special-case optimization for ascii, except U+007F. This
291
+ // improves performance even for many primarily non-ascii texts,
292
+ // due to use of punctuation and white space characters from the
293
+ // ascii range.
294
+ if ch >= '\u{20}' {
295
+ GC_Any
296
+ } else if ch == '\n' {
297
+ GC_LF
298
+ } else if ch == '\r' {
299
+ GC_CR
300
+ } else {
301
+ GC_Control
302
+ }
303
+ } else {
304
+ // If this char isn't within the cached range, update the cache to the
305
+ // range that includes it.
306
+ if ( ch as u32 ) < self . grapheme_cat_cache . 0 || ( ch as u32 ) > self . grapheme_cat_cache . 1 {
307
+ self . grapheme_cat_cache = gr:: grapheme_category ( ch) ;
308
+ }
309
+ self . grapheme_cat_cache . 2
291
310
}
292
- self . grapheme_cat_cache . 2
293
311
}
294
312
295
313
// Not sure I'm gonna keep this, the advantage over new() seems thin.
You can’t perform that action at this time.
0 commit comments