Computes TIndexEntry hash without temporary strings.

This commit is contained in:
Grzegorz Adam Hankiewicz 2014-05-24 11:52:56 +02:00
commit 489d7e526d

View file

@ -364,15 +364,16 @@ proc cmp(a, b: TIndexEntry): int =
if result == 0: if result == 0:
result = cmpIgnoreStyle(a.link, b.link) result = cmpIgnoreStyle(a.link, b.link)
proc hash(x: TIndexEntry): int = proc hash(x: TIndexEntry): THash =
## Returns the hash for the combined fields of the type. ## Returns the hash for the combined fields of the type.
## ##
## The hash is computed as the concatenated string of all available fields. ## The hash is computed as the chained hash of the individual string hashes.
assert(not x.keyword.isNil) assert(not x.keyword.isNil)
assert(not x.link.isNil) assert(not x.link.isNil)
let value = x.keyword & x.link & (x.linkTitle or "") & (x.linkDesc or "") result = x.keyword.hash !& x.link.hash
result = value.hash result = result !& (x.linkTitle or "").hash
result = result !& (x.linkDesc or "").hash
result = !$result
proc `<-`(a: var TIndexEntry, b: TIndexEntry) = proc `<-`(a: var TIndexEntry, b: TIndexEntry) =
shallowCopy a.keyword, b.keyword shallowCopy a.keyword, b.keyword