aboutsummaryrefslogtreecommitdiffstats
path: root/pathtools/lists.go
diff options
context:
space:
mode:
authorColin Cross <ccross@android.com>2015-04-14 16:00:47 -0700
committerColin Cross <ccross@android.com>2015-04-15 11:03:06 -0700
commit7bf6f6213017775c4392119d3970ab719ba9074a (patch)
treeaf16a579d7d696c6d42edc3dcbc7ddac8d1a6c3c /pathtools/lists.go
parent8ac0a812f120fd7f2a1da07f6228352dee4b84d0 (diff)
downloadandroid_build_blueprint-7bf6f6213017775c4392119d3970ab719ba9074a.tar.gz
android_build_blueprint-7bf6f6213017775c4392119d3970ab719ba9074a.tar.bz2
android_build_blueprint-7bf6f6213017775c4392119d3970ab719ba9074a.zip
Replace ReplaceExtension regexp with manual string operations
regexp is overkill for a simple extension replacement, just find the last '.' and add the new extension after it. Saves 5% cpu time on one workload. Change-Id: Ic299c9ec5132d15bbea2c9c7778c000d6fdf509a
Diffstat (limited to 'pathtools/lists.go')
-rw-r--r--pathtools/lists.go12
1 files changed, 6 insertions, 6 deletions
diff --git a/pathtools/lists.go b/pathtools/lists.go
index 36be1e7..fbde88a 100644
--- a/pathtools/lists.go
+++ b/pathtools/lists.go
@@ -16,11 +16,7 @@ package pathtools
import (
"path/filepath"
- "regexp"
-)
-
-var (
- replaceRegexp = regexp.MustCompile(`\.[^\.]+$`)
+ "strings"
)
// PrefixPaths returns a list of paths consisting of prefix joined with each
@@ -43,5 +39,9 @@ func ReplaceExtensions(paths []string, extension string) []string {
}
func ReplaceExtension(path string, extension string) string {
- return replaceRegexp.ReplaceAllString(path, "."+extension)
+ dot := strings.LastIndex(path, ".")
+ if dot == -1 {
+ return path
+ }
+ return path[:dot+1] + extension
}