Skip to content

Commit 490c4ce

Browse files
committed
Merge pull request #1348 from mgreter/fix/hash-functions
Fix remaining hash functions to use `hash_combine`
2 parents b8236e7 + 2c1de6f commit 490c4ce

File tree

1 file changed

+55
-35
lines changed

1 file changed

+55
-35
lines changed

ast.hpp

Lines changed: 55 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -770,6 +770,10 @@ namespace Sass {
770770
{ concrete_type(LIST); }
771771
string type() { return is_arglist_ ? "arglist" : "list"; }
772772
static string type_name() { return "list"; }
773+
const char* sep_string(bool compressed = false) const {
774+
return separator() == SASS_COMMA ?
775+
(compressed ? "," : ", ") : " ";
776+
}
773777
bool is_invisible() const { return empty(); }
774778
Expression* value_at_index(size_t i);
775779

@@ -779,12 +783,11 @@ namespace Sass {
779783

780784
virtual size_t hash()
781785
{
782-
if (hash_ > 0) return hash_;
783-
784-
hash_ = std::hash<string>()(separator() == SASS_COMMA ? "comma" : "space");
785-
for (size_t i = 0, L = length(); i < L; ++i)
786-
hash_combine(hash_, (elements()[i])->hash());
787-
786+
if (hash_ == 0) {
787+
hash_ = std::hash<string>()(sep_string());
788+
for (size_t i = 0, L = length(); i < L; ++i)
789+
hash_combine(hash_, (elements()[i])->hash());
790+
}
788791
return hash_;
789792
}
790793

@@ -832,11 +835,11 @@ namespace Sass {
832835

833836
virtual size_t hash()
834837
{
835-
if (hash_ > 0) return hash_;
836-
837-
for (auto key : keys()) {
838-
hash_combine(hash_, key->hash());
839-
hash_combine(hash_, at(key)->hash());
838+
if (hash_ == 0) {
839+
for (auto key : keys()) {
840+
hash_combine(hash_, key->hash());
841+
hash_combine(hash_, at(key)->hash());
842+
}
840843
}
841844

842845
return hash_;
@@ -904,8 +907,11 @@ namespace Sass {
904907
}
905908
virtual size_t hash()
906909
{
907-
if (hash_ > 0) return hash_;
908-
hash_ = left()->hash() ^ right()->hash() ^ std::hash<size_t>()(type_);
910+
if (hash_ == 0) {
911+
hash_ = std::hash<size_t>()(type_);
912+
hash_combine(hash_, left()->hash());
913+
hash_combine(hash_, right()->hash());
914+
}
909915
return hash_;
910916
}
911917
ATTACH_OPERATIONS()
@@ -950,8 +956,10 @@ namespace Sass {
950956
}
951957
virtual size_t hash()
952958
{
953-
if (hash_ > 0) return hash_;
954-
hash_ = operand()->hash() ^ std::hash<size_t>()(type_);
959+
if (hash_ == 0) {
960+
hash_ = std::hash<size_t>()(type_);
961+
hash_combine(hash_, operand()->hash());
962+
};
955963
return hash_;
956964
}
957965
ATTACH_OPERATIONS()
@@ -992,10 +1000,10 @@ namespace Sass {
9921000

9931001
virtual size_t hash()
9941002
{
995-
if (hash_ > 0) return hash_;
996-
997-
hash_ = std::hash<string>()(name()) ^ value()->hash();
998-
1003+
if (hash_ == 0) {
1004+
hash_ = std::hash<string>()(name());
1005+
hash_combine(hash_, value()->hash());
1006+
}
9991007
return hash_;
10001008
}
10011009

@@ -1060,12 +1068,11 @@ namespace Sass {
10601068

10611069
virtual size_t hash()
10621070
{
1063-
if (hash_ > 0) return hash_;
1064-
1065-
hash_ = std::hash<string>()(name());
1066-
for (auto argument : arguments()->elements())
1067-
hash_combine(hash_, argument->hash());
1068-
1071+
if (hash_ == 0) {
1072+
hash_ = std::hash<string>()(name());
1073+
for (auto argument : arguments()->elements())
1074+
hash_combine(hash_, argument->hash());
1075+
}
10691076
return hash_;
10701077
}
10711078

@@ -1150,7 +1157,10 @@ namespace Sass {
11501157

11511158
virtual size_t hash()
11521159
{
1153-
if (hash_ == 0) hash_ = std::hash<string>()(value_) ^ std::hash<int>()(type_);
1160+
if (hash_ == 0) {
1161+
hash_ = std::hash<string>()(value_);
1162+
hash_combine(hash_, std::hash<int>()(type_));
1163+
}
11541164
return hash_;
11551165
}
11561166

@@ -1186,7 +1196,9 @@ namespace Sass {
11861196

11871197
virtual size_t hash()
11881198
{
1189-
if (hash_ == 0) hash_ = std::hash<double>()(value_);
1199+
if (hash_ == 0) {
1200+
hash_ = std::hash<double>()(value_);
1201+
}
11901202
return hash_;
11911203
}
11921204

@@ -1228,7 +1240,12 @@ namespace Sass {
12281240

12291241
virtual size_t hash()
12301242
{
1231-
if (hash_ == 0) hash_ = std::hash<double>()(r_) ^ std::hash<double>()(g_) ^ std::hash<double>()(b_) ^ std::hash<double>()(a_);
1243+
if (hash_ == 0) {
1244+
hash_ = std::hash<double>()(a_);
1245+
hash_combine(hash_, std::hash<double>()(r_));
1246+
hash_combine(hash_, std::hash<double>()(g_));
1247+
hash_combine(hash_, std::hash<double>()(b_));
1248+
}
12321249
return hash_;
12331250
}
12341251

@@ -1267,7 +1284,9 @@ namespace Sass {
12671284

12681285
virtual size_t hash()
12691286
{
1270-
if (hash_ == 0) hash_ = std::hash<bool>()(value_);
1287+
if (hash_ == 0) {
1288+
hash_ = std::hash<bool>()(value_);
1289+
}
12711290
return hash_;
12721291
}
12731292

@@ -1323,11 +1342,10 @@ namespace Sass {
13231342

13241343
virtual size_t hash()
13251344
{
1326-
if (hash_ > 0) return hash_;
1327-
1328-
for (auto string : elements())
1329-
hash_combine(hash_, string->hash());
1330-
1345+
if (hash_ == 0) {
1346+
for (auto string : elements())
1347+
hash_combine(hash_, string->hash());
1348+
}
13311349
return hash_;
13321350
}
13331351

@@ -1375,7 +1393,9 @@ namespace Sass {
13751393

13761394
virtual size_t hash()
13771395
{
1378-
if (hash_ == 0) hash_ = std::hash<string>()(value_);
1396+
if (hash_ == 0) {
1397+
hash_ = std::hash<string>()(value_);
1398+
}
13791399
return hash_;
13801400
}
13811401

0 commit comments

Comments
 (0)