Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

configmap with alphabetical order #5334

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 2 additions & 4 deletions kyaml/yaml/datamap.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,9 @@ import (
// SortedMapKeys returns a sorted slice of keys to the given map.
// Writing this function never gets old.
func SortedMapKeys(m map[string]string) []string {
keys := make([]string, len(m))
i := 0
keys := make([]string, 0, len(m))
for k := range m {
keys[i] = k
i++
keys = append(keys, k)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think this code change is a functional change, it looks like it does exactly the same thing functionally as it did previously, but I believe your version has slightly worse performance because we are appending to an array rather than having a prebuilt array.

You can test this out in go playground and see that it functionally does the same thing: https://go.dev/play/p/1BBr3XTnHBS

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've check the link and the functional did do the same things... the performance should be relativity same as we pre-allocate capacity but I didn't test it so I can't guarantee.

the configmap data is getting sort and loaded here, but I don't know where it get un-sorted when return to the user..

}
sort.Strings(keys)
return keys
Expand Down
Loading