diff options
author | Yu Liu <yudiliu@google.com> | 2023-05-23 23:27:34 +0000 |
---|---|---|
committer | Android (Google) Code Review <android-gerrit@google.com> | 2023-05-23 23:27:34 +0000 |
commit | 4f0c490ac995a5a8dab4479f2bd5ecbdd5c8e4d9 (patch) | |
tree | e22174d2099a3ec58335d054fa5e71e746e00f0b | |
parent | 66902d7ec06f6299467120c02b345832f9bf5c46 (diff) | |
parent | ee84727d9578548e48607b907c0cf1bc0551bfcc (diff) | |
download | soong-4f0c490ac995a5a8dab4479f2bd5ecbdd5c8e4d9.tar.gz |
Merge "Do not modify input in-place" into udc-dev
-rw-r--r-- | android/util.go | 3 |
1 files changed, 3 insertions, 0 deletions
diff --git a/android/util.go b/android/util.go index 20d007d74..08a3521a5 100644 --- a/android/util.go +++ b/android/util.go @@ -280,6 +280,8 @@ func RemoveFromList(s string, list []string) (bool, []string) { // FirstUniqueStrings returns all unique elements of a slice of strings, keeping the first copy of // each. It modifies the slice contents in place, and returns a subslice of the original slice. func FirstUniqueStrings(list []string) []string { + // Do not moodify the input in-place, operate on a copy instead. + list = CopyOf(list) // 128 was chosen based on BenchmarkFirstUniqueStrings results. if len(list) > 128 { return firstUniqueStringsMap(list) @@ -336,6 +338,7 @@ func LastUniqueStrings(list []string) []string { // SortedUniqueStrings returns what the name says func SortedUniqueStrings(list []string) []string { + // FirstUniqueStrings creates a copy of `list`, so the input remains untouched. unique := FirstUniqueStrings(list) sort.Strings(unique) return unique |