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:
parent
40ec61685c
commit
e003334429
|
@ -339,12 +339,10 @@ func (d *ResourceData) getSet(
|
||||||
var indexMap map[int]int
|
var indexMap map[int]int
|
||||||
if len(parts) > 0 {
|
if len(parts) > 0 {
|
||||||
indexMap = make(map[int]int)
|
indexMap = make(map[int]int)
|
||||||
}
|
|
||||||
|
|
||||||
// Build the set from all the items using the given hash code
|
// Build the set from all the items using the given hash code
|
||||||
for i, v := range list {
|
for i, v := range list {
|
||||||
code := s.add(v)
|
code := s.add(v)
|
||||||
if indexMap != nil {
|
|
||||||
indexMap[code] = i
|
indexMap[code] = i
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue