diff options
author | Junegunn Choi <junegunn.c@gmail.com> | 2015-08-02 14:00:18 +0900 |
---|---|---|
committer | Junegunn Choi <junegunn.c@gmail.com> | 2015-08-02 14:00:18 +0900 |
commit | 0ea66329b84cc6e4f8ff61ee99c00bb238070247 (patch) | |
tree | 72c3bc62ec491246390b56b2aac5b33645839503 /src/item.go | |
parent | 634670e3ea51a2fa1498a3de0c074b819828e2d8 (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/item.go')
-rw-r--r-- | src/item.go | 20 |
1 files changed, 11 insertions, 9 deletions
diff --git a/src/item.go b/src/item.go index 68f52972..96f3d231 100644 --- a/src/item.go +++ b/src/item.go @@ -17,9 +17,9 @@ type colorOffset struct { // Item represents each input line type Item struct { - text *string - origText *string - transformed *[]Token + text []rune + origText *[]rune + transformed []Token index uint32 offsets []Offset colors []ansiOffset @@ -66,19 +66,19 @@ func (i *Item) Rank(cache bool) Rank { // It is guaranteed that .transformed in not null in normal execution if i.transformed != nil { lenSum := 0 - for _, token := range *i.transformed { - lenSum += len(*token.text) + for _, token := range i.transformed { + lenSum += len(token.text) } tiebreak = uint16(lenSum) } else { - tiebreak = uint16(len(*i.text)) + tiebreak = uint16(len(i.text)) } case byBegin: // We can't just look at i.offsets[0][0] because it can be an inverse term tiebreak = uint16(minBegin) case byEnd: if prevEnd > 0 { - tiebreak = uint16(1 + len(*i.text) - prevEnd) + tiebreak = uint16(1 + len(i.text) - prevEnd) } else { // Empty offsets due to inverse terms. tiebreak = 1 @@ -100,10 +100,12 @@ func (i *Item) AsString() string { // StringPtr returns the pointer to the original string func (i *Item) StringPtr() *string { + runes := i.text if i.origText != nil { - return i.origText + runes = *i.origText } - return i.text + str := string(runes) + return &str } func (item *Item) colorOffsets(color int, bold bool, current bool) []colorOffset { |