浏览代码

Ignore internal fields when comparing value types

Raul Silvera 9 年前
父节点
当前提交
52e540e0d5
共有 1 个文件被更改,包括 8 次插入3 次删除
  1. 8
    3
      profile/merge.go

+ 8
- 3
profile/merge.go 查看文件

16
 
16
 
17
 import (
17
 import (
18
 	"fmt"
18
 	"fmt"
19
-	"reflect"
20
 	"sort"
19
 	"sort"
21
 	"strconv"
20
 	"strconv"
22
 	"strings"
21
 	"strings"
420
 // returns nil if the profiles are compatible; otherwise an error with
419
 // returns nil if the profiles are compatible; otherwise an error with
421
 // details on the incompatibility.
420
 // details on the incompatibility.
422
 func (p *Profile) compatible(pb *Profile) error {
421
 func (p *Profile) compatible(pb *Profile) error {
423
-	if !reflect.DeepEqual(p.PeriodType, pb.PeriodType) {
422
+	if !equalValueType(p.PeriodType, pb.PeriodType) {
424
 		return fmt.Errorf("incompatible period types %v and %v", p.PeriodType, pb.PeriodType)
423
 		return fmt.Errorf("incompatible period types %v and %v", p.PeriodType, pb.PeriodType)
425
 	}
424
 	}
426
 
425
 
429
 	}
428
 	}
430
 
429
 
431
 	for i := range p.SampleType {
430
 	for i := range p.SampleType {
432
-		if !reflect.DeepEqual(p.SampleType[i], pb.SampleType[i]) {
431
+		if !equalValueType(p.SampleType[i], pb.SampleType[i]) {
433
 			return fmt.Errorf("incompatible sample types %v and %v", p.SampleType, pb.SampleType)
432
 			return fmt.Errorf("incompatible sample types %v and %v", p.SampleType, pb.SampleType)
434
 		}
433
 		}
435
 	}
434
 	}
436
 
435
 
437
 	return nil
436
 	return nil
438
 }
437
 }
438
+
439
+// equalValueType returns true if the two value types are semantically
440
+// equal. It ignores the internal fields used during encode/decode.
441
+func equalValueType(st1, st2 *ValueType) bool {
442
+	return st1.Type == st2.Type && st1.Unit == st2.Unit
443
+}