ShouldKeepExistingBuldFileForDir look up by dir
instead of scanning every entry in the map for prefix-match, search each ancestor of the dir
Bug: N/A
Test: bazel_test.go#TestShouldKeepExistingBuildFileForDir()
Change-Id: I7c9afa456cca5a70624ae1e9c9b96c43b0110c1e
diff --git a/android/bazel.go b/android/bazel.go
index d30cb80..60989f6 100644
--- a/android/bazel.go
+++ b/android/bazel.go
@@ -341,16 +341,19 @@
// Exact dir match
return true
}
+ var i int
// Check if subtree match
- for prefix, recursive := range a.keepExistingBuildFile {
- if recursive {
- if strings.HasPrefix(dir, prefix+"/") {
- return true
- }
+ for {
+ j := strings.Index(dir[i:], "/")
+ if j == -1 {
+ return false //default
+ }
+ prefix := dir[0 : i+j]
+ i = i + j + 1 // skip the "/"
+ if recursive, ok := a.keepExistingBuildFile[prefix]; ok && recursive {
+ return true
}
}
- // Default
- return false
}
var bp2BuildAllowListKey = NewOnceKey("Bp2BuildAllowlist")