revert stdlib changes which are not required anymore

This commit is contained in:
Andreas Rumpf
2020-04-01 14:34:24 +02:00
parent 66f18037b3
commit 484548c784
6 changed files with 20 additions and 21 deletions

View File

@@ -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.} =

View File

@@ -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

View File

@@ -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)

View File

@@ -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)

View File

@@ -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():

View File

@@ -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