mirror of
https://github.com/kovidgoyal/kitty
synced 2026-07-24 09:18:08 +02:00
Use a branchless check for unicode range
This commit is contained in:
@@ -7,6 +7,19 @@ import (
|
||||
|
||||
var _ = fmt.Print
|
||||
|
||||
func ensure_char_in_range(value uint32) uint32 {
|
||||
// Branchless: if (value > MAX_UNICODE) value = 0
|
||||
diff := int64(value) - UNICODE_LIMIT
|
||||
// The right shift gives all ones for negative diff and all zeros for positive diff
|
||||
mask := uint32(diff >> 63)
|
||||
return value & mask
|
||||
}
|
||||
|
||||
func CharPropsFor(ch rune) CharProps {
|
||||
q := ensure_char_in_range(uint32(ch))
|
||||
return charprops_for(q)
|
||||
}
|
||||
|
||||
func IteratorOverGraphemes(text string) iter.Seq[string] {
|
||||
var s GraphemeSegmentationResult
|
||||
start_pos := 0
|
||||
@@ -39,7 +52,7 @@ func (s *GraphemeSegmentationResult) Reset() {
|
||||
|
||||
func (s GraphemeSegmentationResult) Step(ch CharProps) GraphemeSegmentationResult {
|
||||
key := grapheme_segmentation_key(s, ch)
|
||||
return GraphemeSegmentationResultFor(key)
|
||||
return graphemesegmentationresult_for(key)
|
||||
}
|
||||
|
||||
func Runewidth(code rune) int {
|
||||
|
||||
Reference in New Issue
Block a user