From e0033344290423663be4a0ac1f96db62941b6953 Mon Sep 17 00:00:00 2001 From: Sander van Harmelen Date: Thu, 16 Oct 2014 11:54:36 +0200 Subject: [PATCH] Shaving off some unneeded calls, saving CPU cycles MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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? --- helper/schema/resource_data.go | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/helper/schema/resource_data.go b/helper/schema/resource_data.go index deb331a05..0bc012f1a 100644 --- a/helper/schema/resource_data.go +++ b/helper/schema/resource_data.go @@ -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 } }