fixes #21393 and misc style changes (#21419)

* fixes #21393 and misc style changes

* progress

---------

Co-authored-by: ringabout <43030857+ringabout@users.noreply.github.com>
This commit is contained in:
Andreas Rumpf 2023-02-24 09:02:15 +01:00 • committed by GitHub
commit 8a19ac2070
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
11 changed files with 70 additions and 61 deletions

View file

@ -247,7 +247,7 @@ proc hash*[T](x: ptr[T]): Hash {.inline.} =
when defined(nimPreviewHashRef) or defined(nimdoc):
proc hash*[T](x: ref[T]): Hash {.inline.} =
## Efficient `hash` overload.
##
##
## .. important:: Use `-d:nimPreviewHashRef` to
## enable hashing `ref`s. It is expected that this behavior
## becomes the new default in upcoming versions.
@ -536,6 +536,7 @@ proc hash*[T: tuple | object | proc](x: T): Hash =
elif T is (proc):
result = hash(pointer(x))
else:
result = 0
for f in fields(x):
result = result !& hash(f)
result = !$result
@ -551,6 +552,7 @@ proc hash*[A](x: openArray[A]): Hash =
else:
result = murmurHash(toOpenArrayByte(x, 0, x.high))
else:
result = 0
for a in x:
result = result !& hash(a)
result = !$result
@ -583,6 +585,7 @@ proc hash*[A](aBuf: openArray[A], sPos, ePos: int): Hash =
proc hash*[A](x: set[A]): Hash =
## Efficient hashing of sets.
## There must be a `hash` proc defined for the element type `A`.
result = 0
for it in items(x):
result = result !& hash(it)
result = !$result