Skip to content

Commit

Permalink
reduce hash collisions for css vars
Browse files Browse the repository at this point in the history
  • Loading branch information
evanw committed Jan 18, 2023
1 parent a98870a commit a6a2f2f
Showing 1 changed file with 19 additions and 5 deletions.
24 changes: 19 additions & 5 deletions internal/css_ast/css_ast.go
Original file line number Diff line number Diff line change
Expand Up @@ -476,8 +476,22 @@ func (a *RDeclaration) Equal(rule R) bool {
}

func (r *RDeclaration) Hash() (uint32, bool) {
hash := uint32(7)
hash = helpers.HashCombine(hash, uint32(r.Key))
var hash uint32
if r.Key == DUnknown {
if r.Important {
hash = uint32(7)
} else {
hash = uint32(8)
}
hash = helpers.HashCombineString(hash, r.KeyText)
} else {
if r.Important {
hash = uint32(9)
} else {
hash = uint32(10)
}
hash = helpers.HashCombine(hash, uint32(r.Key))
}
hash = HashTokens(hash, r.Value)
return hash, true
}
Expand All @@ -492,7 +506,7 @@ func (a *RBadDeclaration) Equal(rule R) bool {
}

func (r *RBadDeclaration) Hash() (uint32, bool) {
hash := uint32(8)
hash := uint32(11)
hash = HashTokens(hash, r.Tokens)
return hash, true
}
Expand All @@ -507,7 +521,7 @@ func (a *RComment) Equal(rule R) bool {
}

func (r *RComment) Hash() (uint32, bool) {
hash := uint32(9)
hash := uint32(12)
hash = helpers.HashCombineString(hash, r.Text)
return hash, true
}
Expand Down Expand Up @@ -538,7 +552,7 @@ func (a *RAtLayer) Equal(rule R) bool {
}

func (r *RAtLayer) Hash() (uint32, bool) {
hash := uint32(10)
hash := uint32(13)
hash = helpers.HashCombine(hash, uint32(len(r.Names)))
for _, parts := range r.Names {
hash = helpers.HashCombine(hash, uint32(len(parts)))
Expand Down

0 comments on commit a6a2f2f

Please sign in to comment.