refactor: replace shallowCopy with something else

This commit is contained in:
jangko 2022-10-14 20:06:40 +07:00
parent 64b56d866c
commit d238693571
No known key found for this signature in database
GPG Key ID: 31702AE10541E6B9
2 changed files with 5 additions and 4 deletions

View File

@ -132,6 +132,7 @@ proc sendNeighbours*(d: DiscoveryProtocol, node: Node, neighbours: seq[Node]) =
const MAX_NEIGHBOURS_PER_PACKET = 12 # TODO: Implement a smarter way to compute it const MAX_NEIGHBOURS_PER_PACKET = 12 # TODO: Implement a smarter way to compute it
type Neighbour = tuple[ip: IpAddress, udpPort, tcpPort: Port, pk: PublicKey] type Neighbour = tuple[ip: IpAddress, udpPort, tcpPort: Port, pk: PublicKey]
var nodes = newSeqOfCap[Neighbour](MAX_NEIGHBOURS_PER_PACKET) var nodes = newSeqOfCap[Neighbour](MAX_NEIGHBOURS_PER_PACKET)
when not defined(nimSeqsV2):
shallow(nodes) shallow(nodes)
template flush() = template flush() =

View File

@ -482,10 +482,10 @@ proc len*(r: RoutingTable): int =
proc moveRight[T](arr: var openArray[T], a, b: int) = proc moveRight[T](arr: var openArray[T], a, b: int) =
## In `arr` move elements in range [a, b] right by 1. ## In `arr` move elements in range [a, b] right by 1.
var t: T var t: T
shallowCopy(t, arr[b + 1]) t = system.move(arr[b + 1])
for i in countdown(b, a): for i in countdown(b, a):
shallowCopy(arr[i + 1], arr[i]) arr[i + 1] = system.move(arr[i])
shallowCopy(arr[a], t) arr[a] = system.move(t)
proc setJustSeen*(r: RoutingTable, n: Node) = proc setJustSeen*(r: RoutingTable, n: Node) =
## Move `n` to the head (most recently seen) of its bucket. ## Move `n` to the head (most recently seen) of its bucket.