Skip to content

Commit

Permalink
struct Equals checks for identity before value checking
Browse files Browse the repository at this point in the history
  • Loading branch information
langmartin committed Apr 11, 2019
1 parent e89dbb2 commit 0767a46
Showing 1 changed file with 9 additions and 12 deletions.
21 changes: 9 additions & 12 deletions nomad/structs/structs.go
Original file line number Diff line number Diff line change
Expand Up @@ -1792,25 +1792,26 @@ func (r *Resources) Merge(other *Resources) {

// COMPAT(0.10): Remove in 0.10
func (r *Resources) Equals(o *Resources) bool {
if r == nil && o == nil {
if r == o {
return true
}
if r == nil || o == nil {
return false
}
if r.CPU == o.CPU &&
return r.CPU == o.CPU &&
r.MemoryMB == o.MemoryMB &&
r.DiskMB == o.DiskMB &&
r.IOPS == o.IOPS &&
r.Networks.Equals(&o.Networks) &&
r.Devices.Equals(&o.Devices) {
return true
}
return false
r.Devices.Equals(&o.Devices)
}

// Equals ResourceDevices as set on Name
// COMPAT(0.10): Remove in 0.10
// ResourceDevices are part of Resources
type ResourceDevices []*RequestedDevice

// COMPAT(0.10): Remove in 0.10
// Equals ResourceDevices as set on Name
func (d *ResourceDevices) Equals(o *ResourceDevices) bool {
if d == nil && o == nil {
return true
Expand Down Expand Up @@ -2081,10 +2082,6 @@ func (n *NetworkResource) PortLabels() map[string]int {
// Networks defined for a task on the Resources struct.
type Networks []*NetworkResource

// COMPAT(0.10): Remove in 0.10
// ResourceDevices are part of Resources
type ResourceDevices []*RequestedDevice

// Port assignment and IP for the given label or empty values.
func (ns Networks) Port(label string) (string, int) {
for _, n := range ns {
Expand Down Expand Up @@ -2345,7 +2342,7 @@ func (n *NodeResources) Equals(o *NodeResources) bool {
}

func (n *Networks) Equals(o *Networks) bool {
if n == nil && o == nil {
if n == o {
return true
}
if n == nil || o == nil {
Expand Down

0 comments on commit 0767a46

Please sign in to comment.