|
53 | 53 | namespace Sass {
|
54 | 54 | using namespace std;
|
55 | 55 |
|
| 56 | + // from boost (functional/hash): |
| 57 | + // http://www.boost.org/doc/libs/1_35_0/doc/html/hash/combine.html |
| 58 | + // Boost Software License - Version 1.0 |
| 59 | + // http://www.boost.org/users/license.html |
| 60 | + template <typename T> |
| 61 | + void hash_combine (std::size_t& seed, const T& val) |
| 62 | + { |
| 63 | + seed ^= std::hash<T>()(val) + 0x9e3779b9 |
| 64 | + + (seed<<6) + (seed>>2); |
| 65 | + } |
| 66 | + |
56 | 67 | //////////////////////////////////////////////////////////
|
57 | 68 | // Abstract base class for all abstract syntax tree nodes.
|
58 | 69 | //////////////////////////////////////////////////////////
|
@@ -137,7 +148,7 @@ namespace std {
|
137 | 148 | {
|
138 | 149 | bool operator()( Sass::Expression* lhs, Sass::Expression* rhs) const
|
139 | 150 | {
|
140 |
| - return *lhs == *rhs; |
| 151 | + return lhs->hash() == rhs->hash(); |
141 | 152 | }
|
142 | 153 | };
|
143 | 154 | }
|
@@ -768,7 +779,7 @@ namespace Sass {
|
768 | 779 | hash_ = std::hash<string>()(separator() == COMMA ? "comma" : "space");
|
769 | 780 |
|
770 | 781 | for (size_t i = 0, L = length(); i < L; ++i)
|
771 |
| - hash_ ^= (elements()[i])->hash(); |
| 782 | + hash_combine(hash_, (elements()[i])->hash()); |
772 | 783 |
|
773 | 784 | return hash_;
|
774 | 785 | }
|
@@ -819,8 +830,10 @@ namespace Sass {
|
819 | 830 | {
|
820 | 831 | if (hash_ > 0) return hash_;
|
821 | 832 |
|
822 |
| - for (auto key : keys()) |
823 |
| - hash_ ^= key->hash() ^ at(key)->hash(); |
| 833 | + for (auto key : keys()) { |
| 834 | + hash_combine(hash_, key->hash()); |
| 835 | + hash_combine(hash_, at(key)->hash()); |
| 836 | + } |
824 | 837 |
|
825 | 838 | return hash_;
|
826 | 839 | }
|
@@ -1085,7 +1098,7 @@ namespace Sass {
|
1085 | 1098 |
|
1086 | 1099 | hash_ = std::hash<string>()(name());
|
1087 | 1100 | for (auto argument : arguments()->elements())
|
1088 |
| - hash_ ^= argument->hash(); |
| 1101 | + hash_combine(hash_, argument->hash()); |
1089 | 1102 |
|
1090 | 1103 | return hash_;
|
1091 | 1104 | }
|
@@ -1347,7 +1360,7 @@ namespace Sass {
|
1347 | 1360 | if (hash_ > 0) return hash_;
|
1348 | 1361 |
|
1349 | 1362 | for (auto string : elements())
|
1350 |
| - hash_ ^= string->hash(); |
| 1363 | + hash_combine(hash_, string->hash()); |
1351 | 1364 |
|
1352 | 1365 | return hash_;
|
1353 | 1366 | }
|
|
0 commit comments