diff options
author | bptato <nincsnevem662@gmail.com> | 2023-06-29 13:39:58 +0200 |
---|---|---|
committer | bptato <nincsnevem662@gmail.com> | 2023-06-29 13:51:55 +0200 |
commit | 19068fd7d803a157de671e189e01731bc903ba9e (patch) | |
tree | aae00bec40a00b67586373199cfe6d9789e19013 /src/encoding | |
parent | 1dd9eba6aba9760339fbef9bbd4244108fac2eab (diff) | |
download | chawan-19068fd7d803a157de671e189e01731bc903ba9e.tar.gz |
Factor out map search, remove sugar
Diffstat (limited to 'src/encoding')
-rw-r--r-- | src/encoding/encoderstream.nim | 8 |
1 files changed, 2 insertions, 6 deletions
diff --git a/src/encoding/encoderstream.nim b/src/encoding/encoderstream.nim index 57f27dd1..56d4c3da 100644 --- a/src/encoding/encoderstream.nim +++ b/src/encoding/encoderstream.nim @@ -5,6 +5,7 @@ import streams import unicode import data/charset +import utils/map # EncoderStream encodes utf-32 to the specified encoding. type @@ -57,12 +58,7 @@ template append_byte(stream: EncoderStream, c: int, stream.append_byte cast[uint8](c), oq, olen, n func findPair[U, V](map: seq[(U, V)], c: uint32): int = - when not (typeof(c) is U): - if c > cast[typeof(c)](high(U)): - return -1 - return binarySearch(map, cast[U](c), - proc(a: tuple[ucs: U, val: V], b: U): int = - cmp(a.ucs, b)) + return searchInMap(map, cast[U](c)) proc handleError(stream: EncoderStream, oq: ptr UncheckedArray[uint8], olen: int, n: var int, c: uint32) = |