mirror of
				https://github.com/optim-enterprises-bv/kubernetes.git
				synced 2025-11-03 19:58:17 +00:00 
			
		
		
		
	Merge pull request #129628 from 249043822/br004
remove duplicate getAttrsFunc calls to reduce temporary memory allocations
This commit is contained in:
		@@ -29,7 +29,6 @@ import (
 | 
			
		||||
	metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
 | 
			
		||||
	"k8s.io/apimachinery/pkg/fields"
 | 
			
		||||
	"k8s.io/apimachinery/pkg/labels"
 | 
			
		||||
	"k8s.io/apimachinery/pkg/runtime"
 | 
			
		||||
	"k8s.io/apimachinery/pkg/runtime/schema"
 | 
			
		||||
	"k8s.io/apimachinery/pkg/util/wait"
 | 
			
		||||
	"k8s.io/apimachinery/pkg/watch"
 | 
			
		||||
@@ -288,10 +287,6 @@ func TestCacheWatcherStoppedOnDestroy(t *testing.T) {
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func TestResourceVersionAfterInitEvents(t *testing.T) {
 | 
			
		||||
	getAttrsFunc := func(obj runtime.Object) (labels.Set, fields.Set, error) {
 | 
			
		||||
		return nil, nil, nil
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	const numObjects = 10
 | 
			
		||||
	store := cache.NewIndexer(storeElementKey, storeElementIndexers(nil))
 | 
			
		||||
 | 
			
		||||
@@ -300,7 +295,7 @@ func TestResourceVersionAfterInitEvents(t *testing.T) {
 | 
			
		||||
		store.Add(elem)
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	wci, err := newCacheIntervalFromStore(numObjects, store, getAttrsFunc, "", false)
 | 
			
		||||
	wci, err := newCacheIntervalFromStore(numObjects, store, "", false)
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		t.Fatal(err)
 | 
			
		||||
	}
 | 
			
		||||
 
 | 
			
		||||
@@ -752,7 +752,7 @@ func (w *watchCache) getAllEventsSinceLocked(resourceVersion uint64, key string,
 | 
			
		||||
// that covers the entire storage state.
 | 
			
		||||
// This function assumes to be called under the watchCache lock.
 | 
			
		||||
func (w *watchCache) getIntervalFromStoreLocked(key string, matchesSingle bool) (*watchCacheInterval, error) {
 | 
			
		||||
	ci, err := newCacheIntervalFromStore(w.resourceVersion, w.store, w.getAttrsFunc, key, matchesSingle)
 | 
			
		||||
	ci, err := newCacheIntervalFromStore(w.resourceVersion, w.store, key, matchesSingle)
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		return nil, err
 | 
			
		||||
	}
 | 
			
		||||
 
 | 
			
		||||
@@ -21,9 +21,6 @@ import (
 | 
			
		||||
	"sort"
 | 
			
		||||
	"sync"
 | 
			
		||||
 | 
			
		||||
	"k8s.io/apimachinery/pkg/fields"
 | 
			
		||||
	"k8s.io/apimachinery/pkg/labels"
 | 
			
		||||
	"k8s.io/apimachinery/pkg/runtime"
 | 
			
		||||
	"k8s.io/apimachinery/pkg/watch"
 | 
			
		||||
)
 | 
			
		||||
 | 
			
		||||
@@ -106,7 +103,6 @@ type watchCacheInterval struct {
 | 
			
		||||
	initialEventsEndBookmark *watchCacheEvent
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
type attrFunc func(runtime.Object) (labels.Set, fields.Set, error)
 | 
			
		||||
type indexerFunc func(int) *watchCacheEvent
 | 
			
		||||
type indexValidator func(int) bool
 | 
			
		||||
 | 
			
		||||
@@ -140,10 +136,9 @@ func (s sortableWatchCacheEvents) Swap(i, j int) {
 | 
			
		||||
// returned by Next() need to be events from a List() done on the underlying store of
 | 
			
		||||
// the watch cache.
 | 
			
		||||
// The items returned in the interval will be sorted by Key.
 | 
			
		||||
func newCacheIntervalFromStore(resourceVersion uint64, store storeIndexer, getAttrsFunc attrFunc, key string, matchesSingle bool) (*watchCacheInterval, error) {
 | 
			
		||||
func newCacheIntervalFromStore(resourceVersion uint64, store storeIndexer, key string, matchesSingle bool) (*watchCacheInterval, error) {
 | 
			
		||||
	buffer := &watchCacheIntervalBuffer{}
 | 
			
		||||
	var allItems []interface{}
 | 
			
		||||
 | 
			
		||||
	if matchesSingle {
 | 
			
		||||
		item, exists, err := store.GetByKey(key)
 | 
			
		||||
		if err != nil {
 | 
			
		||||
@@ -162,15 +157,11 @@ func newCacheIntervalFromStore(resourceVersion uint64, store storeIndexer, getAt
 | 
			
		||||
		if !ok {
 | 
			
		||||
			return nil, fmt.Errorf("not a storeElement: %v", elem)
 | 
			
		||||
		}
 | 
			
		||||
		objLabels, objFields, err := getAttrsFunc(elem.Object)
 | 
			
		||||
		if err != nil {
 | 
			
		||||
			return nil, err
 | 
			
		||||
		}
 | 
			
		||||
		buffer.buffer[i] = &watchCacheEvent{
 | 
			
		||||
			Type:            watch.Added,
 | 
			
		||||
			Object:          elem.Object,
 | 
			
		||||
			ObjLabels:       objLabels,
 | 
			
		||||
			ObjFields:       objFields,
 | 
			
		||||
			ObjLabels:       elem.Labels,
 | 
			
		||||
			ObjFields:       elem.Fields,
 | 
			
		||||
			Key:             elem.Key,
 | 
			
		||||
			ResourceVersion: resourceVersion,
 | 
			
		||||
		}
 | 
			
		||||
 
 | 
			
		||||
@@ -392,7 +392,7 @@ func TestCacheIntervalNextFromStore(t *testing.T) {
 | 
			
		||||
		store.Add(elem)
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	wci, err := newCacheIntervalFromStore(rv, store, getAttrsFunc, "", false)
 | 
			
		||||
	wci, err := newCacheIntervalFromStore(rv, store, "", false)
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		t.Fatal(err)
 | 
			
		||||
	}
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user