From 19068fd7d803a157de671e189e01731bc903ba9e Mon Sep 17 00:00:00 2001 From: bptato Date: Thu, 29 Jun 2023 13:39:58 +0200 Subject: Factor out map search, remove sugar --- src/encoding/encoderstream.nim | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) (limited to 'src/encoding') 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) = -- cgit 1.4.1-2-gfad0