mirror of https://github.com/status-im/nim-eth.git
avoid allocation in `hash(ValidIpAddress)` (#433)
* avoid allocation in `hash(ValidIpAddress)` While casually browsing the profiler output, to my great surprise I found that an allocating string conversion function (gasp!) in the hash function for ip addresses - this PR carefully excises this evil construct from the codebase. * bump nim version
This commit is contained in:
parent
139c6fa2a8
commit
2baa4c02a1
|
@ -16,7 +16,10 @@ type
|
||||||
limit*: uint
|
limit*: uint
|
||||||
ips: Table[ValidIpAddress, uint]
|
ips: Table[ValidIpAddress, uint]
|
||||||
|
|
||||||
func hash(ip: ValidIpAddress): Hash = hash($ip)
|
func hash(ip: ValidIpAddress): Hash =
|
||||||
|
case ip.family
|
||||||
|
of IpAddressFamily.IPv6: hash(ip.address_v6)
|
||||||
|
of IpAddressFamily.IPv4: hash(ip.address_v4)
|
||||||
|
|
||||||
func inc*(ipLimits: var IpLimits, ip: ValidIpAddress): bool =
|
func inc*(ipLimits: var IpLimits, ip: ValidIpAddress): bool =
|
||||||
let val = ipLimits.ips.getOrDefault(ip, 0)
|
let val = ipLimits.ips.getOrDefault(ip, 0)
|
||||||
|
|
Loading…
Reference in New Issue