mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-22 11:21:47 +00:00
optimize nil and empty also for slices
brings to parity with maps
This commit is contained in:
parent
48786d90da
commit
a4819996a8
@ -169,6 +169,18 @@ func (e Equalities) deepValueEqual(v1, v2 reflect.Value, visited map[visit]bool,
|
|||||||
if v1.IsNil() != v2.IsNil() {
|
if v1.IsNil() != v2.IsNil() {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Optimize nil and empty cases
|
||||||
|
// Two lists that are BOTH nil are equal
|
||||||
|
// No need to check v2 is nil since v1.IsNil == v2.IsNil from above
|
||||||
|
if v1.IsNil() {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
|
// Two lists that are both empty and both non nil are equal
|
||||||
|
if v1.Len() == 0 || v2.Len() == 0 {
|
||||||
|
return true
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if v1.Len() != v2.Len() {
|
if v1.Len() != v2.Len() {
|
||||||
return false
|
return false
|
||||||
@ -210,13 +222,13 @@ func (e Equalities) deepValueEqual(v1, v2 reflect.Value, visited map[visit]bool,
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Optimize nil and empty cases
|
// Optimize nil and empty cases
|
||||||
// Two lists that are BOTH nil are equal
|
// Two maps that are BOTH nil are equal
|
||||||
// No need to check v2 is nil since v1.IsNil == v2.IsNil from above
|
// No need to check v2 is nil since v1.IsNil == v2.IsNil from above
|
||||||
if v1.IsNil() {
|
if v1.IsNil() {
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
// Two lists that are both empty and both non nil are equal
|
// Two maps that are both empty and both non nil are equal
|
||||||
if v1.Len() == 0 || v2.Len() == 0 {
|
if v1.Len() == 0 || v2.Len() == 0 {
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user