diff options
author | Araq <rumpf_a@web.de> | 2012-07-17 17:26:02 +0200 |
---|---|---|
committer | Araq <rumpf_a@web.de> | 2012-07-17 17:26:02 +0200 |
commit | 832da8a303793ac23a662dd76ff93caa2d5eb764 (patch) | |
tree | 2ca48cbeffcb8b378d5b44ee5b7b6cf208263aae /lib | |
parent | 19e57bf70dddecdd0834b06099c2fd5f8ee0ad9e (diff) | |
download | Nim-832da8a303793ac23a662dd76ff93caa2d5eb764.tar.gz |
equality and hashing for closures
Diffstat (limited to 'lib')
-rwxr-xr-x | lib/pure/hashes.nim | 7 | ||||
-rwxr-xr-x | lib/system.nim | 1 |
2 files changed, 8 insertions, 0 deletions
diff --git a/lib/pure/hashes.nim b/lib/pure/hashes.nim index 7d4613f50..1249ff73b 100755 --- a/lib/pure/hashes.nim +++ b/lib/pure/hashes.nim @@ -67,6 +67,13 @@ proc hash*(x: Pointer): THash {.inline.} = else: result = (cast[THash](x)) shr 3 # skip the alignment +proc hash*[T: proc](x: T): THash {.inline.} = + ## efficient hashing of proc vars; closures are supported too. + when T is "closure": + result = hash(rawProc(x)) !& hash(rawEnv(x)) + else: + result = hash(pointer(x)) + proc hash*(x: int): THash {.inline.} = ## efficient hashing of integers result = x diff --git a/lib/system.nim b/lib/system.nim index dbbe75a57..b6b695d9b 100755 --- a/lib/system.nim +++ b/lib/system.nim @@ -1348,6 +1348,7 @@ proc isNil*(x: string): bool {.noSideEffect, magic: "IsNil".} proc isNil*[T](x: ptr T): bool {.noSideEffect, magic: "IsNil".} proc isNil*(x: pointer): bool {.noSideEffect, magic: "IsNil".} proc isNil*(x: cstring): bool {.noSideEffect, magic: "IsNil".} +proc isNil*[T: proc](x: T): bool {.noSideEffect, magic: "IsNil".} ## Fast check whether `x` is nil. This is sometimes more efficient than ## ``== nil``. |