about summary refs log tree commit diff stats
path: root/src/encoding
diff options
context:
space:
mode:
authorbptato <nincsnevem662@gmail.com>2023-06-29 13:39:58 +0200
committerbptato <nincsnevem662@gmail.com>2023-06-29 13:51:55 +0200
commit19068fd7d803a157de671e189e01731bc903ba9e (patch)
treeaae00bec40a00b67586373199cfe6d9789e19013 /src/encoding
parent1dd9eba6aba9760339fbef9bbd4244108fac2eab (diff)
downloadchawan-19068fd7d803a157de671e189e01731bc903ba9e.tar.gz
Factor out map search, remove sugar
Diffstat (limited to 'src/encoding')
-rw-r--r--src/encoding/encoderstream.nim8
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) =