Make a fast path for isDirective
2.92 secs => 2.8 secs for
ONE_SHOT_MAKEFILE=bionic/Android.mk repo/android.sh time kati -n
diff --git a/parser.go b/parser.go
index e5a033b..5cd1b44 100644
--- a/parser.go
+++ b/parser.go
@@ -356,6 +356,15 @@
func (p *parser) isDirective(line string, directives map[string]func(*parser, string)) bool {
stripped := strings.TrimLeft(line, " \t")
+ // Fast paths.
+ // TODO: Consider using a trie.
+ if len(stripped) == 0 {
+ return false
+ }
+ if ch := stripped[0]; ch != 'i' && ch != '-' && ch != 's' && ch != 'e' && ch != 'd' {
+ return false
+ }
+
for prefix, _ := range directives {
if strings.HasPrefix(stripped, prefix) {
return true