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/cc/compiler.go b/cc/compiler.go
index 1ced451..c1a8d96 100644
--- a/cc/compiler.go
+++ b/cc/compiler.go
@@ -241,12 +241,7 @@
// Return true if the module is in the WarningAllowedProjects.
func warningsAreAllowed(subdir string) bool {
subdir += "/"
- for _, prefix := range config.WarningAllowedProjects {
- if strings.HasPrefix(subdir, prefix) {
- return true
- }
- }
- return false
+ return android.HasAnyPrefix(subdir, config.WarningAllowedProjects)
}
func addToModuleList(ctx ModuleContext, key android.OnceKey, module string) {
@@ -515,7 +510,7 @@
// Exclude directories from manual binder interface whitelisting.
//TODO(b/145621474): Move this check into IInterface.h when clang-tidy no longer uses absolute paths.
- if android.PrefixInList(ctx.ModuleDir(), allowedManualInterfacePaths) {
+ if android.HasAnyPrefix(ctx.ModuleDir(), allowedManualInterfacePaths) {
flags.Local.CFlags = append(flags.Local.CFlags, "-DDO_NOT_CHECK_MANUAL_BINDER_INTERFACES")
}
@@ -604,16 +599,12 @@
func isThirdParty(path string) bool {
thirdPartyDirPrefixes := []string{"external/", "vendor/", "hardware/"}
- for _, prefix := range thirdPartyDirPrefixes {
- if strings.HasPrefix(path, prefix) {
- for _, prefix := range thirdPartyDirPrefixExceptions {
- if prefix.MatchString(path) {
- return false
- }
+ if android.HasAnyPrefix(path, thirdPartyDirPrefixes) {
+ for _, prefix := range thirdPartyDirPrefixExceptions {
+ if prefix.MatchString(path) {
+ return false
}
- break
}
}
-
return true
}