Make CopyOf generic
Test: util_test.go
Change-Id: If8f2534ec454903eb967dc9ec0c8708096d1baff
diff --git a/android/util.go b/android/util.go
index c4ce71a..0080467 100644
--- a/android/util.go
+++ b/android/util.go
@@ -25,12 +25,12 @@
)
// CopyOf returns a new slice that has the same contents as s.
-func CopyOf(s []string) []string {
+func CopyOf[T any](s []T) []T {
// If the input is nil, return nil and not an empty list
if s == nil {
return s
}
- return append([]string{}, s...)
+ return append([]T{}, s...)
}
// Concat returns a new slice concatenated from the two input slices. It does not change the input
diff --git a/android/util_test.go b/android/util_test.go
index bee31a9..0e28b56 100644
--- a/android/util_test.go
+++ b/android/util_test.go
@@ -385,7 +385,7 @@
emptyList := []string{}
copyOfEmptyList := CopyOf(emptyList)
AssertBoolEquals(t, "Copy of an empty list should be an empty list and not nil", true, copyOfEmptyList != nil)
- copyOfNilList := CopyOf(nil)
+ copyOfNilList := CopyOf([]string(nil))
AssertBoolEquals(t, "Copy of a nil list should be a nil list and not an empty list", true, copyOfNilList == nil)
}
diff --git a/dexpreopt/dexpreopt.go b/dexpreopt/dexpreopt.go
index 20737e3..7db609b 100644
--- a/dexpreopt/dexpreopt.go
+++ b/dexpreopt/dexpreopt.go
@@ -630,5 +630,3 @@
}
return false
}
-
-var copyOf = android.CopyOf
diff --git a/java/dexpreopt_config.go b/java/dexpreopt_config.go
index 9100e87..28f50d7 100644
--- a/java/dexpreopt_config.go
+++ b/java/dexpreopt_config.go
@@ -250,8 +250,6 @@
var defaultBootclasspathKey = android.NewOnceKey("defaultBootclasspath")
-var copyOf = android.CopyOf
-
func init() {
android.RegisterMakeVarsProvider(pctx, dexpreoptConfigMakevars)
}
diff --git a/java/robolectric.go b/java/robolectric.go
index 6bbe872..0041af4 100644
--- a/java/robolectric.go
+++ b/java/robolectric.go
@@ -299,7 +299,7 @@
func (r *robolectricTest) generateRoboSrcJar(ctx android.ModuleContext, outputFile android.WritablePath,
instrumentedApp *AndroidApp) {
- srcJarArgs := copyOf(instrumentedApp.srcJarArgs)
+ srcJarArgs := android.CopyOf(instrumentedApp.srcJarArgs)
srcJarDeps := append(android.Paths(nil), instrumentedApp.srcJarDeps...)
for _, m := range ctx.GetDirectDepsWithTag(roboCoverageLibsTag) {