forked from GsDevKit/BitmapCharacterSet
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathadd..st
More file actions
35 lines (30 loc) · 1.09 KB
/
add..st
File metadata and controls
35 lines (30 loc) · 1.09 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
adding
add: aCharacter
| asciiValue |
"optimized for speed with inlining; do not refactor"
(asciiValue := aCharacter asciiValue) < 256
ifTrue: [
(byteCharacters at: asciiValue + 1)
ifFalse: [tally := tally + 1].
byteCharacters
at: asciiValue + 1
put: true]
ifFalse: [| byteIndex byte bitmask |
"256 // 8 - 31 = 1 (first index), (256 + 8) // 8 - 31 = 2 (second), etc
(with 'bitShift: -3' used over '// 8' for speed)"
byteIndex := (asciiValue bitShift: -3) - 31.
(wideCharacters == nil
or: [byteIndex > wideCharacters size])
ifTrue: [self growWideCharacterBitmapTo: (byteIndex * 1.5) asInteger].
"raises an error if asciiValue > 16r10FFFF"
byte := wideCharacters at: byteIndex.
"for the byte bitmask, left shift 1 by 7 - (asciiValue \\ 8)
(with 'bitAnd: 7' used over '\\ 8' for speed)"
bitmask := 1 bitShift: 7 - (asciiValue bitAnd: 7).
"increment the tally if the character is not already present"
(byte bitAnd: bitmask) == 0
ifTrue: [tally := tally + 1].
wideCharacters
at: byteIndex
put: (byte bitOr: bitmask)].
^ aCharacter.