summaryrefslogtreecommitdiffstats
path: root/src/ansi.go
diff options
context:
space:
mode:
authorJunegunn Choi <junegunn.c@gmail.com>2015-08-02 14:00:18 +0900
committerJunegunn Choi <junegunn.c@gmail.com>2015-08-02 14:00:18 +0900
commit0ea66329b84cc6e4f8ff61ee99c00bb238070247 (patch)
tree72c3bc62ec491246390b56b2aac5b33645839503 /src/ansi.go
parent634670e3ea51a2fa1498a3de0c074b819828e2d8 (diff)
Performance tuning - eager rune array conversion
> wc -l /tmp/list2 2594098 /tmp/list2 > time cat /tmp/list2 | fzf-0.10.1-darwin_amd64 -fqwerty > /dev/null real 0m5.418s user 0m10.990s sys 0m1.302s > time cat /tmp/list2 | fzf-head -fqwerty > /dev/null real 0m4.862s user 0m6.619s sys 0m0.982s
Diffstat (limited to 'src/ansi.go')
-rw-r--r--src/ansi.go13
1 files changed, 6 insertions, 7 deletions
diff --git a/src/ansi.go b/src/ansi.go
index a80de478..876229f1 100644
--- a/src/ansi.go
+++ b/src/ansi.go
@@ -36,7 +36,7 @@ func init() {
ansiRegex = regexp.MustCompile("\x1b\\[[0-9;]*[mK]")
}
-func extractColor(str *string, state *ansiState) (*string, []ansiOffset, *ansiState) {
+func extractColor(str string, state *ansiState) (string, []ansiOffset, *ansiState) {
var offsets []ansiOffset
var output bytes.Buffer
@@ -45,9 +45,9 @@ func extractColor(str *string, state *ansiState) (*string, []ansiOffset, *ansiSt
}
idx := 0
- for _, offset := range ansiRegex.FindAllStringIndex(*str, -1) {
- output.WriteString((*str)[idx:offset[0]])
- newState := interpretCode((*str)[offset[0]:offset[1]], state)
+ for _, offset := range ansiRegex.FindAllStringIndex(str, -1) {
+ output.WriteString(str[idx:offset[0]])
+ newState := interpretCode(str[offset[0]:offset[1]], state)
if !newState.equals(state) {
if state != nil {
@@ -69,7 +69,7 @@ func extractColor(str *string, state *ansiState) (*string, []ansiOffset, *ansiSt
idx = offset[1]
}
- rest := (*str)[idx:]
+ rest := str[idx:]
if len(rest) > 0 {
output.WriteString(rest)
if state != nil {
@@ -77,8 +77,7 @@ func extractColor(str *string, state *ansiState) (*string, []ansiOffset, *ansiSt
(&offsets[len(offsets)-1]).offset[1] = int32(utf8.RuneCount(output.Bytes()))
}
}
- outputStr := output.String()
- return &outputStr, offsets, state
+ return output.String(), offsets, state
}
func interpretCode(ansiCode string, prevState *ansiState) *ansiState {