forked from GsDevKit/BitmapCharacterSet
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathremove.ifAbsent..st
More file actions
32 lines (28 loc) · 997 Bytes
/
remove.ifAbsent..st
File metadata and controls
32 lines (28 loc) · 997 Bytes
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
removing
remove: aCharacter ifAbsent: aBlock
| asciiValue |
"optimized for speed with inlining; do not refactor"
(asciiValue := aCharacter asciiValue) < 256
ifTrue: [
(byteCharacters at: asciiValue + 1)
ifFalse: [^ aBlock value].
byteCharacters
at: asciiValue + 1
put: false]
ifFalse: [| byteIndex byte bitmask |
wideCharacters
ifNil: [^ aBlock value].
"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 size
ifTrue: [^ aBlock value].
"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).
((byte := wideCharacters at: byteIndex) bitAnd: bitmask) == 0
ifTrue: [^ aBlock value].
wideCharacters
at: byteIndex
put: (byte bitAnd: bitmask bitInvert)].
tally := tally - 1.
^ aCharacter.