optimise some code
This commit is contained in:
		| @@ -26,7 +26,7 @@ const ( | |||||||
| 	ImpersonateUserHeader = "Impersonate-User" | 	ImpersonateUserHeader = "Impersonate-User" | ||||||
|  |  | ||||||
| 	// ImpersonateUIDHeader is used to impersonate a particular UID during an API server request. | 	// ImpersonateUIDHeader is used to impersonate a particular UID during an API server request. | ||||||
| 	ImpersonateUidHeader = "Impersonate-Uid" | 	ImpersonateUIDHeader = "Impersonate-Uid" | ||||||
|  |  | ||||||
| 	// ImpersonateGroupHeader is used to impersonate a particular group during an API server request. | 	// ImpersonateGroupHeader is used to impersonate a particular group during an API server request. | ||||||
| 	// It can be repeated multiplied times for multiple groups. | 	// It can be repeated multiplied times for multiple groups. | ||||||
|   | |||||||
| @@ -103,7 +103,7 @@ var ( | |||||||
| 		}, | 		}, | ||||||
| 		[]string{"action"}) | 		[]string{"action"}) | ||||||
|  |  | ||||||
| 	// TerminatedPodsWithTrackingFinalizer records the addition and removal of | 	// TerminatedPodsTrackingFinalizerTotal records the addition and removal of | ||||||
| 	// terminated pods that have the finalizer batch.kubernetes.io/job-tracking, | 	// terminated pods that have the finalizer batch.kubernetes.io/job-tracking, | ||||||
| 	// regardless of whether they are owned by a Job. | 	// regardless of whether they are owned by a Job. | ||||||
| 	TerminatedPodsTrackingFinalizerTotal = metrics.NewCounterVec( | 	TerminatedPodsTrackingFinalizerTotal = metrics.NewCounterVec( | ||||||
|   | |||||||
| @@ -152,7 +152,7 @@ func (m *BiMultimap) Put(key Key, labels map[string]string) { | |||||||
| 		m.selectingByLabeled[labelsKey] = selecting | 		m.selectingByLabeled[labelsKey] = selecting | ||||||
| 	} | 	} | ||||||
| 	selecting := m.selectingByLabeled[labelsKey] | 	selecting := m.selectingByLabeled[labelsKey] | ||||||
| 	selecting.refCount += 1 | 	selecting.refCount++ | ||||||
| 	for _, sObject := range selecting.objects { | 	for _, sObject := range selecting.objects { | ||||||
| 		// Associate labeled with selecting. | 		// Associate labeled with selecting. | ||||||
| 		labeled := m.labeledBySelecting[sObject.selectorKey] | 		labeled := m.labeledBySelecting[sObject.selectorKey] | ||||||
| @@ -185,7 +185,7 @@ func (m *BiMultimap) delete(key Key) { | |||||||
| 		// Delete selectingObject to labeledObject association. | 		// Delete selectingObject to labeledObject association. | ||||||
| 		delete(m.labeledBySelecting[selectorKey].objects, key) | 		delete(m.labeledBySelecting[selectorKey].objects, key) | ||||||
| 	} | 	} | ||||||
| 	m.selectingByLabeled[labelsKey].refCount -= 1 | 	m.selectingByLabeled[labelsKey].refCount-- | ||||||
| 	// Garbage collect labeledObject to selectingObject associations. | 	// Garbage collect labeledObject to selectingObject associations. | ||||||
| 	if m.selectingByLabeled[labelsKey].refCount == 0 { | 	if m.selectingByLabeled[labelsKey].refCount == 0 { | ||||||
| 		delete(m.selectingByLabeled, labelsKey) | 		delete(m.selectingByLabeled, labelsKey) | ||||||
| @@ -246,7 +246,7 @@ func (m *BiMultimap) PutSelector(key Key, selector pkglabels.Selector) { | |||||||
| 		m.labeledBySelecting[selectorKey] = labeled | 		m.labeledBySelecting[selectorKey] = labeled | ||||||
| 	} | 	} | ||||||
| 	labeled := m.labeledBySelecting[selectorKey] | 	labeled := m.labeledBySelecting[selectorKey] | ||||||
| 	labeled.refCount += 1 | 	labeled.refCount++ | ||||||
| 	for _, labeledObject := range labeled.objects { | 	for _, labeledObject := range labeled.objects { | ||||||
| 		// Associate selecting with labeled. | 		// Associate selecting with labeled. | ||||||
| 		selecting := m.selectingByLabeled[labeledObject.labelsKey] | 		selecting := m.selectingByLabeled[labeledObject.labelsKey] | ||||||
| @@ -280,7 +280,7 @@ func (m *BiMultimap) deleteSelector(key Key) { | |||||||
| 		// Delete labeledObject to selectingObject association. | 		// Delete labeledObject to selectingObject association. | ||||||
| 		delete(m.selectingByLabeled[labelsKey].objects, key) | 		delete(m.selectingByLabeled[labelsKey].objects, key) | ||||||
| 	} | 	} | ||||||
| 	m.labeledBySelecting[selectorKey].refCount -= 1 | 	m.labeledBySelecting[selectorKey].refCount-- | ||||||
| 	// Garbage collect selectingObjects to labeledObject associations. | 	// Garbage collect selectingObjects to labeledObject associations. | ||||||
| 	if m.labeledBySelecting[selectorKey].refCount == 0 { | 	if m.labeledBySelecting[selectorKey].refCount == 0 { | ||||||
| 		delete(m.labeledBySelecting, selectorKey) | 		delete(m.labeledBySelecting, selectorKey) | ||||||
|   | |||||||
| @@ -623,11 +623,11 @@ func unorderedEqual(as, bs []Key) bool { | |||||||
| 	} | 	} | ||||||
| 	aMap := make(map[Key]int) | 	aMap := make(map[Key]int) | ||||||
| 	for _, a := range as { | 	for _, a := range as { | ||||||
| 		aMap[a] += 1 | 		aMap[a]++ | ||||||
| 	} | 	} | ||||||
| 	bMap := make(map[Key]int) | 	bMap := make(map[Key]int) | ||||||
| 	for _, b := range bs { | 	for _, b := range bs { | ||||||
| 		bMap[b] += 1 | 		bMap[b]++ | ||||||
| 	} | 	} | ||||||
| 	if len(aMap) != len(bMap) { | 	if len(aMap) != len(bMap) { | ||||||
| 		return false | 		return false | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user
	 bzsuni
					bzsuni