mirror of https://github.com/k3s-io/k3s
Merge pull request #64688 from hzxuzhonghu/resourceList-opt
Automatic merge from submit-queue (batch tested with PRs 64688, 64451, 64504, 64506, 56358). If you want to cherry-pick this change to another branch, please follow the instructions <a href="https://github.com/kubernetes/community/blob/master/contributors/devel/cherry-picks.md">here</a>. resourceQuota: optimize Equals of ResourceLists optimize ResourceList Equals function: reduce a loop. **Release note**: ```release-note NONE ```pull/8/head
commit
ef4442f214
|
@ -27,6 +27,10 @@ import (
|
|||
|
||||
// Equals returns true if the two lists are equivalent
|
||||
func Equals(a api.ResourceList, b api.ResourceList) bool {
|
||||
if len(a) != len(b) {
|
||||
return false
|
||||
}
|
||||
|
||||
for key, value1 := range a {
|
||||
value2, found := b[key]
|
||||
if !found {
|
||||
|
@ -36,20 +40,16 @@ func Equals(a api.ResourceList, b api.ResourceList) bool {
|
|||
return false
|
||||
}
|
||||
}
|
||||
for key, value1 := range b {
|
||||
value2, found := a[key]
|
||||
if !found {
|
||||
return false
|
||||
}
|
||||
if value1.Cmp(value2) != 0 {
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
return true
|
||||
}
|
||||
|
||||
// V1Equals returns true if the two lists are equivalent
|
||||
func V1Equals(a v1.ResourceList, b v1.ResourceList) bool {
|
||||
if len(a) != len(b) {
|
||||
return false
|
||||
}
|
||||
|
||||
for key, value1 := range a {
|
||||
value2, found := b[key]
|
||||
if !found {
|
||||
|
@ -59,15 +59,7 @@ func V1Equals(a v1.ResourceList, b v1.ResourceList) bool {
|
|||
return false
|
||||
}
|
||||
}
|
||||
for key, value1 := range b {
|
||||
value2, found := a[key]
|
||||
if !found {
|
||||
return false
|
||||
}
|
||||
if value1.Cmp(value2) != 0 {
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
return true
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue