From 484548c784f69cadc1f6480a24e99183a0e6a930 Mon Sep 17 00:00:00 2001 From: Andreas Rumpf Date: Wed, 1 Apr 2020 14:34:24 +0200 Subject: [PATCH] revert stdlib changes which are not required anymore --- lib/pure/collections/sequtils.nim | 5 +++-- lib/pure/collections/sharedtables.nim | 18 ++++++++++-------- lib/pure/ioselects/ioselectors_epoll.nim | 3 ++- lib/pure/ioselects/ioselectors_kqueue.nim | 3 ++- lib/pure/ioselects/ioselectors_select.nim | 8 +------- lib/pure/parsecsv.nim | 4 ++-- 6 files changed, 20 insertions(+), 21 deletions(-) diff --git a/lib/pure/collections/sequtils.nim b/lib/pure/collections/sequtils.nim index 893f31389155b..e32c784c65c4c 100644 --- a/lib/pure/collections/sequtils.nim +++ b/lib/pure/collections/sequtils.nim @@ -371,8 +371,9 @@ proc map*[T, S](s: openArray[T], op: proc (x: T): S {.closure.}): b = map(a, proc(x: int): string = $x) assert b == @["1", "2", "3", "4"] - result = newSeqOfCap[S](s.len) - for elem in s: result.add op(elem) + newSeq(result, s.len) + for i in 0 ..< s.len: + result[i] = op(s[i]) proc apply*[T](s: var openArray[T], op: proc (x: var T) {.closure.}) {.inline.} = diff --git a/lib/pure/collections/sharedtables.nim b/lib/pure/collections/sharedtables.nim index 96f934f503bf0..2a1c0543f3b3b 100644 --- a/lib/pure/collections/sharedtables.nim +++ b/lib/pure/collections/sharedtables.nim @@ -77,7 +77,8 @@ template withValue*[A, B](t: var SharedTable[A, B], key: A, try: var hc: Hash var index = rawGet(t, key, hc) - if index >= 0: + let hasKey = index >= 0 + if hasKey: var value {.inject.} = addr(t.data[index].val) body finally: @@ -103,7 +104,8 @@ template withValue*[A, B](t: var SharedTable[A, B], key: A, try: var hc: Hash var index = rawGet(t, key, hc) - if index >= 0: + let hasKey = index >= 0 + if hasKey: var value {.inject.} = addr(t.data[index].val) body1 else: @@ -117,13 +119,13 @@ proc mget*[A, B](t: var SharedTable[A, B], key: A): var B = withLock t: var hc: Hash var index = rawGet(t, key, hc) - if index >= 0: - result = t.data[index].val + let hasKey = index >= 0 + if hasKey: result = t.data[index].val + if not hasKey: + when compiles($key): + raise newException(KeyError, "key not found: " & $key) else: - when compiles($key): - raise newException(KeyError, "key not found: " & $key) - else: - raise newException(KeyError, "key not found") + raise newException(KeyError, "key not found") proc mgetOrPut*[A, B](t: var SharedTable[A, B], key: A, val: B): var B = ## retrieves value at ``t[key]`` or puts ``val`` if not present, either way diff --git a/lib/pure/ioselects/ioselectors_epoll.nim b/lib/pure/ioselects/ioselectors_epoll.nim index 002bddac52fce..bf13cc83e8161 100644 --- a/lib/pure/ioselects/ioselectors_epoll.nim +++ b/lib/pure/ioselects/ioselectors_epoll.nim @@ -502,7 +502,8 @@ proc contains*[T](s: Selector[T], fd: SocketHandle|int): bool {.inline.} = proc getData*[T](s: Selector[T], fd: SocketHandle|int): var T = let fdi = int(fd) s.checkFd(fdi) - result = s.fds[fdi].data + if fdi in s: + result = s.fds[fdi].data proc setData*[T](s: Selector[T], fd: SocketHandle|int, data: T): bool = let fdi = int(fd) diff --git a/lib/pure/ioselects/ioselectors_kqueue.nim b/lib/pure/ioselects/ioselectors_kqueue.nim index c5e19a011320d..83e15d479c75e 100644 --- a/lib/pure/ioselects/ioselectors_kqueue.nim +++ b/lib/pure/ioselects/ioselectors_kqueue.nim @@ -600,7 +600,8 @@ proc contains*[T](s: Selector[T], fd: SocketHandle|int): bool {.inline.} = proc getData*[T](s: Selector[T], fd: SocketHandle|int): var T = let fdi = int(fd) s.checkFd(fdi) - result = s.fds[fdi].data + if fdi in s: + result = s.fds[fdi].data proc setData*[T](s: Selector[T], fd: SocketHandle|int, data: T): bool = let fdi = int(fd) diff --git a/lib/pure/ioselects/ioselectors_select.nim b/lib/pure/ioselects/ioselectors_select.nim index 6a742df99d5c0..02a853b42948d 100644 --- a/lib/pure/ioselects/ioselectors_select.nim +++ b/lib/pure/ioselects/ioselectors_select.nim @@ -410,17 +410,11 @@ else: body proc getData*[T](s: Selector[T], fd: SocketHandle|int): var T = - # The compiler needs this to prove that all code paths return a value - result = (cast[ptr T](0'u))[] - s.withSelectLock(): let fdi = int(fd) for i in 0..= 0 - result = my.row[index] + if index >= 0: + result = my.row[index] when not defined(testing) and isMainModule: import os