Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix remaining hash functions to use hash_combine #1348

Merged
merged 1 commit into from
Jul 15, 2015
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
90 changes: 55 additions & 35 deletions ast.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -770,6 +770,10 @@ namespace Sass {
{ concrete_type(LIST); }
string type() { return is_arglist_ ? "arglist" : "list"; }
static string type_name() { return "list"; }
const char* sep_string(bool compressed = false) const {
return separator() == SASS_COMMA ?
(compressed ? "," : ", ") : " ";
}
bool is_invisible() const { return empty(); }
Expression* value_at_index(size_t i);

Expand All @@ -779,12 +783,11 @@ namespace Sass {

virtual size_t hash()
{
if (hash_ > 0) return hash_;

hash_ = std::hash<string>()(separator() == SASS_COMMA ? "comma" : "space");
for (size_t i = 0, L = length(); i < L; ++i)
hash_combine(hash_, (elements()[i])->hash());

if (hash_ == 0) {
hash_ = std::hash<string>()(sep_string());
for (size_t i = 0, L = length(); i < L; ++i)
hash_combine(hash_, (elements()[i])->hash());
}
return hash_;
}

Expand Down Expand Up @@ -832,11 +835,11 @@ namespace Sass {

virtual size_t hash()
{
if (hash_ > 0) return hash_;

for (auto key : keys()) {
hash_combine(hash_, key->hash());
hash_combine(hash_, at(key)->hash());
if (hash_ == 0) {
for (auto key : keys()) {
hash_combine(hash_, key->hash());
hash_combine(hash_, at(key)->hash());
}
}

return hash_;
Expand Down Expand Up @@ -904,8 +907,11 @@ namespace Sass {
}
virtual size_t hash()
{
if (hash_ > 0) return hash_;
hash_ = left()->hash() ^ right()->hash() ^ std::hash<size_t>()(type_);
if (hash_ == 0) {
hash_ = std::hash<size_t>()(type_);
hash_combine(hash_, left()->hash());
hash_combine(hash_, right()->hash());
}
return hash_;
}
ATTACH_OPERATIONS()
Expand Down Expand Up @@ -950,8 +956,10 @@ namespace Sass {
}
virtual size_t hash()
{
if (hash_ > 0) return hash_;
hash_ = operand()->hash() ^ std::hash<size_t>()(type_);
if (hash_ == 0) {
hash_ = std::hash<size_t>()(type_);
hash_combine(hash_, operand()->hash());
};
return hash_;
}
ATTACH_OPERATIONS()
Expand Down Expand Up @@ -992,10 +1000,10 @@ namespace Sass {

virtual size_t hash()
{
if (hash_ > 0) return hash_;

hash_ = std::hash<string>()(name()) ^ value()->hash();

if (hash_ == 0) {
hash_ = std::hash<string>()(name());
hash_combine(hash_, value()->hash());
}
return hash_;
}

Expand Down Expand Up @@ -1060,12 +1068,11 @@ namespace Sass {

virtual size_t hash()
{
if (hash_ > 0) return hash_;

hash_ = std::hash<string>()(name());
for (auto argument : arguments()->elements())
hash_combine(hash_, argument->hash());

if (hash_ == 0) {
hash_ = std::hash<string>()(name());
for (auto argument : arguments()->elements())
hash_combine(hash_, argument->hash());
}
return hash_;
}

Expand Down Expand Up @@ -1150,7 +1157,10 @@ namespace Sass {

virtual size_t hash()
{
if (hash_ == 0) hash_ = std::hash<string>()(value_) ^ std::hash<int>()(type_);
if (hash_ == 0) {
hash_ = std::hash<string>()(value_);
hash_combine(hash_, std::hash<int>()(type_));
}
return hash_;
}

Expand Down Expand Up @@ -1186,7 +1196,9 @@ namespace Sass {

virtual size_t hash()
{
if (hash_ == 0) hash_ = std::hash<double>()(value_);
if (hash_ == 0) {
hash_ = std::hash<double>()(value_);
}
return hash_;
}

Expand Down Expand Up @@ -1228,7 +1240,12 @@ namespace Sass {

virtual size_t hash()
{
if (hash_ == 0) hash_ = std::hash<double>()(r_) ^ std::hash<double>()(g_) ^ std::hash<double>()(b_) ^ std::hash<double>()(a_);
if (hash_ == 0) {
hash_ = std::hash<double>()(a_);
hash_combine(hash_, std::hash<double>()(r_));
hash_combine(hash_, std::hash<double>()(g_));
hash_combine(hash_, std::hash<double>()(b_));
}
return hash_;
}

Expand Down Expand Up @@ -1267,7 +1284,9 @@ namespace Sass {

virtual size_t hash()
{
if (hash_ == 0) hash_ = std::hash<bool>()(value_);
if (hash_ == 0) {
hash_ = std::hash<bool>()(value_);
}
return hash_;
}

Expand Down Expand Up @@ -1323,11 +1342,10 @@ namespace Sass {

virtual size_t hash()
{
if (hash_ > 0) return hash_;

for (auto string : elements())
hash_combine(hash_, string->hash());

if (hash_ == 0) {
for (auto string : elements())
hash_combine(hash_, string->hash());
}
return hash_;
}

Expand Down Expand Up @@ -1375,7 +1393,9 @@ namespace Sass {

virtual size_t hash()
{
if (hash_ == 0) hash_ = std::hash<string>()(value_);
if (hash_ == 0) {
hash_ = std::hash<string>()(value_);
}
return hash_;
}

Expand Down