Shaving off some unneeded calls, saving CPU cycles

I know it’s very unlikely that a user will notice the difference, but
why range through the list, generate the set and calculate the
hashcode, only to find out that indexMap == nil (e.g. don’t do anything
with the generated hashcode).

As indexMap is only needed when len(parts) > 0, why not only create and
fill it (in one go) when len(parts) > 0?
This commit is contained in:
Sander van Harmelen 2014-10-16 11:54:36 +02:00
parent 40ec61685c
commit e003334429
1 changed files with 3 additions and 5 deletions

View File

@ -339,12 +339,10 @@ func (d *ResourceData) getSet(
var indexMap map[int]int
if len(parts) > 0 {
indexMap = make(map[int]int)
}
// Build the set from all the items using the given hash code
for i, v := range list {
code := s.add(v)
if indexMap != nil {
// Build the set from all the items using the given hash code
for i, v := range list {
code := s.add(v)
indexMap[code] = i
}
}