summaryrefslogtreecommitdiffstats
path: root/src/ansi.go
diff options
context:
space:
mode:
authorJunegunn Choi <junegunn.c@gmail.com>2016-08-19 02:39:32 +0900
committerJunegunn Choi <junegunn.c@gmail.com>2016-08-19 02:39:32 +0900
commit37dc273148df0893053bf5cda0582a23f5c2b2d2 (patch)
treed90f5e96fa97de429265461268b1a6db2703cb4c /src/ansi.go
parentf7f01d109eb05c7eae82c243b6b6d5c5951ee707 (diff)
Micro-optimizations
- Make structs smaller - Introduce Result struct and use it to represent matched items instead of reusing Item struct for that purpose - Avoid unnecessary memory allocation - Avoid growing slice from the initial capacity - Code cleanup
Diffstat (limited to 'src/ansi.go')
-rw-r--r--src/ansi.go7
1 files changed, 5 insertions, 2 deletions
diff --git a/src/ansi.go b/src/ansi.go
index 56831eee..0a525671 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, proc func(string, *ansiState) bool) (string, []ansiOffset, *ansiState) {
+func extractColor(str string, state *ansiState, proc func(string, *ansiState) bool) (string, *[]ansiOffset, *ansiState) {
var offsets []ansiOffset
var output bytes.Buffer
@@ -84,7 +84,10 @@ func extractColor(str string, state *ansiState, proc func(string, *ansiState) bo
if proc != nil {
proc(rest, state)
}
- return output.String(), offsets, state
+ if len(offsets) == 0 {
+ return output.String(), nil, state
+ }
+ return output.String(), &offsets, state
}
func interpretCode(ansiCode string, prevState *ansiState) *ansiState {