Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
K
k3s
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Jacklull
k3s
Commits
70b7513c
Commit
70b7513c
authored
Jan 30, 2019
by
wojtekt
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Optimize Index() method to avoid unnecessary copies
parent
d654b49c
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
13 additions
and
6 deletions
+13
-6
thread_safe_store.go
...ing/src/k8s.io/client-go/tools/cache/thread_safe_store.go
+13
-6
No files found.
staging/src/k8s.io/client-go/tools/cache/thread_safe_store.go
View file @
70b7513c
...
@@ -148,12 +148,19 @@ func (c *threadSafeMap) Index(indexName string, obj interface{}) ([]interface{},
...
@@ -148,12 +148,19 @@ func (c *threadSafeMap) Index(indexName string, obj interface{}) ([]interface{},
}
}
index
:=
c
.
indices
[
indexName
]
index
:=
c
.
indices
[
indexName
]
// need to de-dupe the return list. Since multiple keys are allowed, this can happen.
var
returnKeySet
sets
.
String
returnKeySet
:=
sets
.
String
{}
if
len
(
indexKeys
)
==
1
{
for
_
,
indexKey
:=
range
indexKeys
{
// In majority of cases, there is exactly one value matching.
set
:=
index
[
indexKey
]
// Optimize the most common path - deduping is not needed here.
for
_
,
key
:=
range
set
.
UnsortedList
()
{
returnKeySet
=
index
[
indexKeys
[
0
]]
returnKeySet
.
Insert
(
key
)
}
else
{
// Need to de-dupe the return list.
// Since multiple keys are allowed, this can happen.
returnKeySet
=
sets
.
String
{}
for
_
,
indexKey
:=
range
indexKeys
{
for
key
:=
range
index
[
indexKey
]
{
returnKeySet
.
Insert
(
key
)
}
}
}
}
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment