Skip to content

Commit

Permalink
revert stdlib changes which are not required anymore
Browse files Browse the repository at this point in the history
  • Loading branch information
Araq committed Apr 1, 2020
1 parent 66f1803 commit 484548c
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 21 deletions.
5 changes: 3 additions & 2 deletions lib/pure/collections/sequtils.nim
Original file line number Diff line number Diff line change
Expand Up @@ -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.} =
Expand Down
18 changes: 10 additions & 8 deletions lib/pure/collections/sharedtables.nim
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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:
Expand All @@ -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
Expand Down
3 changes: 2 additions & 1 deletion lib/pure/ioselects/ioselectors_epoll.nim
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
3 changes: 2 additions & 1 deletion lib/pure/ioselects/ioselectors_kqueue.nim
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
8 changes: 1 addition & 7 deletions lib/pure/ioselects/ioselectors_select.nim
Original file line number Diff line number Diff line change
Expand Up @@ -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..<FD_SETSIZE:
if s.fds[i].ident == fdi:
result = s.fds[i].data
break

assert cast[uint](addr(result)) != 0
return s.fds[i].data

proc setData*[T](s: Selector[T], fd: SocketHandle|int, data: T): bool =
s.withSelectLock():
Expand Down
4 changes: 2 additions & 2 deletions lib/pure/parsecsv.nim
Original file line number Diff line number Diff line change
Expand Up @@ -338,8 +338,8 @@ proc rowEntry*(my: var CsvParser, entry: string): var string =
strm.close()

let index = my.headers.find(entry)
assert index >= 0
result = my.row[index]
if index >= 0:
result = my.row[index]

when not defined(testing) and isMainModule:
import os
Expand Down

0 comments on commit 484548c

Please sign in to comment.