@@ -523,11 +523,8 @@ func (compare *compare) sequenceNodes(path ytbx.Path, from *yamlv3.Node, to *yam
523523}
524524
525525func (compare * compare ) simpleLists (path ytbx.Path , from * yamlv3.Node , to * yamlv3.Node ) ([]Diff , error ) {
526- removals := make ([]* yamlv3.Node , 0 )
527- additions := make ([]* yamlv3.Node , 0 )
528-
529- fromLength := len (from .Content )
530- toLength := len (to .Content )
526+ var removals , additions []* yamlv3.Node
527+ var fromLength , toLength = len (from .Content ), len (to .Content )
531528
532529 // Special case if both lists only contain one entry, then directly compare
533530 // the two entries with each other
@@ -539,12 +536,25 @@ func (compare *compare) simpleLists(path ytbx.Path, from *yamlv3.Node, to *yamlv
539536 )
540537 }
541538
542- fromLookup := compare .createLookUpMap (from )
543- toLookup := compare .createLookUpMap (to )
539+ var createLookUpMap = func (sequenceNode * yamlv3.Node ) map [uint64 ][]int {
540+ var result = make (map [uint64 ][]int , len (sequenceNode .Content ))
541+ for idx , entry := range sequenceNode .Content {
542+ var hash = compare .calcNodeHash (entry )
543+ if _ , ok := result [hash ]; ! ok {
544+ result [hash ] = []int {}
545+ }
546+
547+ result [hash ] = append (result [hash ], idx )
548+ }
549+
550+ return result
551+ }
552+
553+ fromLookup := createLookUpMap (from )
554+ toLookup := createLookUpMap (to )
544555
545556 // Fill two lists with the hashes of the entries of each list
546- fromCommon := make ([]* yamlv3.Node , 0 , fromLength )
547- toCommon := make ([]* yamlv3.Node , 0 , toLength )
557+ var fromCommon , toCommon []* yamlv3.Node
548558
549559 for idxPos , fromValue := range from .Content {
550560 hash := compare .calcNodeHash (fromValue )
@@ -1038,20 +1048,6 @@ func isEmptyDocument(node *yamlv3.Node) bool {
10381048 return false
10391049}
10401050
1041- func (compare * compare ) createLookUpMap (sequenceNode * yamlv3.Node ) map [uint64 ][]int {
1042- result := make (map [uint64 ][]int , len (sequenceNode .Content ))
1043- for idx , entry := range sequenceNode .Content {
1044- hash := compare .calcNodeHash (entry )
1045- if _ , ok := result [hash ]; ! ok {
1046- result [hash ] = []int {}
1047- }
1048-
1049- result [hash ] = append (result [hash ], idx )
1050- }
1051-
1052- return result
1053- }
1054-
10551051func (compare * compare ) basicType (node * yamlv3.Node ) interface {} {
10561052 switch node .Kind {
10571053 case yamlv3 .DocumentNode :
@@ -1098,7 +1094,7 @@ func (compare *compare) calcNodeHash(node *yamlv3.Node) (hash uint64) {
10981094 hash , err = hashstructure .Hash (compare .basicType (node ), nil )
10991095
11001096 case yamlv3 .ScalarNode :
1101- hash , err = hashstructure .Hash (node .Value , nil )
1097+ hash , err = hashstructure .Hash (node .Tag + "/" + node . Value , nil )
11021098
11031099 case yamlv3 .AliasNode :
11041100 hash = compare .calcNodeHash (followAlias (node ))
0 commit comments