Skip to content
This repository has been archived by the owner on Oct 12, 2022. It is now read-only.

Commit

Permalink
Merge pull request #984 from IgorStepanov/hashOf-aa-safe
Browse files Browse the repository at this point in the history
remove try-catch from AA hashOf
  • Loading branch information
MartinNowak committed Oct 4, 2014
2 parents 244b907 + 9431dfe commit e3c8df5
Showing 1 changed file with 9 additions and 16 deletions.
25 changes: 9 additions & 16 deletions src/core/internal/hash.d
Original file line number Diff line number Diff line change
Expand Up @@ -154,25 +154,18 @@ size_t hashOf(T)(auto ref T val, size_t seed = 0) if (!is(T == enum) && is(T ==
//associative array hash. CTFE depends on base types
size_t hashOf(T)(auto ref T aa, size_t seed = 0) if (!is(T == enum) && __traits(isAssociativeArray, T))
{
try
{
if (!aa.length) return mixHash(0, seed);
size_t h = 0;
if (!aa.length) return mixHash(0, seed);
size_t h = 0;

// The computed hash is independent of the foreach traversal order.
foreach (key, ref val; aa)
{
size_t[2] hpair;
hpair[0] = key.hashOf();
hpair[1] = val.hashOf();
h ^= hpair.hashOf();
}
return mixHash(h, seed);
}
catch (Throwable thr)
// The computed hash is independent of the foreach traversal order.
foreach (key, ref val; aa)
{
assert(0);
size_t[2] hpair;
hpair[0] = key.hashOf();
hpair[1] = val.hashOf();
h ^= hpair.hashOf();
}
return mixHash(h, seed);
}

unittest
Expand Down

0 comments on commit e3c8df5

Please sign in to comment.