minor improve findLiteralChar performance
diff --git a/eval.go b/eval.go
index be7048d..16452ba 100644
--- a/eval.go
+++ b/eval.go
@@ -273,7 +273,7 @@
abuf.Write(b)
continue
}
- eq := findLiteralChar(b, []byte{'='}, true)
+ eq := findLiteralChar(b, '=', 0)
if eq >= 0 {
abuf.Write(b[:eq+1])
if eq+1 < len(b) {
diff --git a/parser.go b/parser.go
index f1d23e4..4d54844 100644
--- a/parser.go
+++ b/parser.go
@@ -152,7 +152,7 @@
func (p *parser) handleRuleOrAssign(line []byte) {
rline := line
var semi []byte
- if i := findLiteralChar(line, []byte{';'}, true); i >= 0 {
+ if i := findLiteralChar(line, ';', 0); i >= 0 {
// preserve after semicolon
semi = append(semi, line[i+1:]...)
rline = concatline(line[:i])
@@ -175,7 +175,7 @@
return false
}
// fmt.Printf("assign: %q=>%q\n", line, aline)
- i := findLiteralChar(aline, []byte{':', '='}, true)
+ i := findLiteralChar(aline, ':', '=')
if i >= 0 {
if aline[i] == '=' {
p.parseAssign(aline, i)
@@ -219,9 +219,9 @@
return
}
var assign *assignAST
- ci := findLiteralChar(line, []byte{':'}, true)
+ ci := findLiteralChar(line, ':', 0)
if ci >= 0 {
- eqi := findLiteralChar(line[ci+1:], []byte{'='}, true)
+ eqi := findLiteralChar(line[ci+1:], '=', 0)
if eqi == 0 {
panic(fmt.Sprintf("unexpected eq after colon: %q", line))
}
diff --git a/pathutil.go b/pathutil.go
index 7dd3df1..591abb2 100644
--- a/pathutil.go
+++ b/pathutil.go
@@ -160,6 +160,9 @@
// AndroidFindCacheInit initializes find cache for android build.
func AndroidFindCacheInit(prunes, leafNames []string) {
+ if !UseFindCache {
+ return
+ }
if leafNames != nil {
androidDefaultLeafNames = leafNames
}
@@ -167,6 +170,9 @@
}
func (c *androidFindCacheT) ready() bool {
+ if !UseFindCache {
+ return false
+ }
if c.files != nil {
return true
}
@@ -177,6 +183,9 @@
}
func (c *androidFindCacheT) leavesReady() bool {
+ if !UseFindCache {
+ return false
+ }
if c.leaves != nil {
return true
}
@@ -187,6 +196,9 @@
}
func (c *androidFindCacheT) init(prunes []string) {
+ if !UseFindCache {
+ return
+ }
c.once.Do(func() {
c.filesch = make(chan []fileInfo, 1)
c.leavesch = make(chan []fileInfo, 1)
diff --git a/strutil.go b/strutil.go
index 6431eb9..02a3a81 100644
--- a/strutil.go
+++ b/strutil.go
@@ -265,15 +265,6 @@
return false
}
-func bytesContains(s []byte, b byte) bool {
- for _, c := range s {
- if c == b {
- return true
- }
- }
- return false
-}
-
func firstWord(line []byte) ([]byte, []byte) {
s := newWordScanner(line)
if s.Scan() {
@@ -283,7 +274,7 @@
return line, nil
}
-func findLiteralChar(s, stop []byte, skipVar bool) int {
+func findLiteralChar(s []byte, stop1, stop2 byte) int {
i := 0
for {
var ch byte
@@ -293,10 +284,13 @@
i += 2
continue
}
- if bytesContains(stop, ch) {
+ if ch == stop1 {
break
}
- if skipVar && ch == '$' {
+ if ch == stop2 {
+ break
+ }
+ if ch == '$' {
break
}
i++