Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitfbba2a6

Browse files
authored
Merge pull request#79 from cessen/ascii_grapheme_optimization
Implement a special-case lookup for ascii grapheme categories.
2 parents485767a +945dbb6 commitfbba2a6

File tree

1 file changed

+23
-5
lines changed

1 file changed

+23
-5
lines changed

‎src/grapheme.rs‎

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -284,12 +284,30 @@ impl GraphemeCursor {
284284

285285
fngrapheme_category(&mutself,ch:char) ->GraphemeCat{
286286
use tables::graphemeas gr;
287-
// If this char isn't within the cached range, update the cache to the
288-
// range that includes it.
289-
if(chasu32) <self.grapheme_cat_cache.0 ||(chasu32) >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+
}elseif ch =='\n'{
297+
GC_LF
298+
}elseif 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(chasu32) <self.grapheme_cat_cache.0 ||(chasu32) >self.grapheme_cat_cache.1{
307+
self.grapheme_cat_cache = gr::grapheme_category(ch);
308+
}
309+
self.grapheme_cat_cache.2
291310
}
292-
self.grapheme_cat_cache.2
293311
}
294312

295313
// Not sure I'm gonna keep this, the advantage over new() seems thin.

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp