Simple refactoring of prefix related functions.
Rename the two prefix-in-list funcs so that their usages are clearer.
Also find and replace all the code that essentially does either.
This introduces additional loops in some places, but I think the added
readability and simplicity outweighs the performance degradation, which
should be negligible anyway.
Test: m nothing
Test: TreeHugger
Change-Id: I37e2276ca0c815105ed0031f23c0b1264b480e4f
diff --git a/java/aar.go b/java/aar.go
index 24c5e7d..a0ec71a 100644
--- a/java/aar.go
+++ b/java/aar.go
@@ -134,15 +134,8 @@
manifestPath android.Path) (compileFlags, linkFlags []string, linkDeps android.Paths,
resDirs, overlayDirs []globbedResourceDir, rroDirs []rroDir, resZips android.Paths) {
- hasVersionCode := false
- hasVersionName := false
- for _, f := range a.aaptProperties.Aaptflags {
- if strings.HasPrefix(f, "--version-code") {
- hasVersionCode = true
- } else if strings.HasPrefix(f, "--version-name") {
- hasVersionName = true
- }
- }
+ hasVersionCode := android.PrefixInList(a.aaptProperties.Aaptflags, "--version-code")
+ hasVersionName := android.PrefixInList(a.aaptProperties.Aaptflags, "--version-name")
// Flags specified in Android.bp
linkFlags = append(linkFlags, a.aaptProperties.Aaptflags...)
@@ -337,7 +330,7 @@
// Extract assets from the resource package output so that they can be used later in aapt2link
// for modules that depend on this one.
- if android.PrefixedStringInList(linkFlags, "-A ") || len(assetPackages) > 0 {
+ if android.PrefixInList(linkFlags, "-A ") || len(assetPackages) > 0 {
assets := android.PathForModuleOut(ctx, "assets.zip")
ctx.Build(pctx, android.BuildParams{
Rule: extractAssetsRule,
diff --git a/java/app.go b/java/app.go
index 02f3e7f..b46a6e1 100755
--- a/java/app.go
+++ b/java/app.go
@@ -273,13 +273,7 @@
aaptLinkFlags := []string{}
// Add TARGET_AAPT_CHARACTERISTICS values to AAPT link flags if they exist and --product flags were not provided.
- hasProduct := false
- for _, f := range a.aaptProperties.Aaptflags {
- if strings.HasPrefix(f, "--product") {
- hasProduct = true
- break
- }
- }
+ hasProduct := android.PrefixInList(a.aaptProperties.Aaptflags, "--product")
if !hasProduct && len(ctx.Config().ProductAAPTCharacteristics()) > 0 {
aaptLinkFlags = append(aaptLinkFlags, "--product", ctx.Config().ProductAAPTCharacteristics())
}
diff --git a/java/droiddoc.go b/java/droiddoc.go
index 959f1c7..6b39314 100644
--- a/java/droiddoc.go
+++ b/java/droiddoc.go
@@ -605,11 +605,8 @@
continue
}
packageName := strings.ReplaceAll(filepath.Dir(src.Rel()), "/", ".")
- for _, pkg := range filterPackages {
- if strings.HasPrefix(packageName, pkg) {
- filtered = append(filtered, src)
- break
- }
+ if android.HasAnyPrefix(packageName, filterPackages) {
+ filtered = append(filtered, src)
}
}
return filtered