Further performance improvements by removing unnecessary copies
Before adoption: this commit came in with the history the project adopted, so no landing records it.
authored by Junegunn Choi · committed by Junegunn Choi · parent a575c0c · Browse files · 5 files·+15 added−8 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
5 files+15 added−8 removed
- other:+15 added−8 removed
Provenance
- Commit
c30e486- Tree
1be9cd9- Author
Junegunn Choi <junegunn.c@gmail.com>- Committer
Junegunn Choi <junegunn.c@gmail.com>- Parent
a575c0c
5 files changed+15 added−8 removed
modified:src/util/chars.go+1 added-1 removed
161 unmodified lines162 func (chars *Chars) ToString() string {163 if runes := chars.optionalRunes(); runes != nil {164 return string(runes)165 }166- return string(chars.slice)166+ return unsafe.String(unsafe.SliceData(chars.slice), len(chars.slice))167 }168 169 func (chars *Chars) ToRunes() []rune {170 if runes := chars.optionalRunes(); runes != nil {28 unmodified linesmodified:src/ansi.go+1 added-1 removed
310 unmodified lines311 if len(s) > 0 {312 // Inlined version of strconv.Atoi() that only handles positive313 // integers and does not allocate on error.314 code := 0315- for _, ch := range []byte(s) {315+ for _, ch := range sbytes(s) {316 ch -= '0'317 if ch > 9 {318 return -1, delimiter, remaining319 }132 unmodified linesmodified:src/core.go+7 added-3 removed
21 unmodified lines22 func ustring(data []byte) string {23 return unsafe.String(unsafe.SliceData(data), len(data))24 }25 26+func sbytes(data string) []byte {27+ return unsafe.Slice(unsafe.StringData(data), len(data))28+}29+30 // Run starts fzf31 func Run(opts *Options, version string, revision string) {32 sort := opts.Sort > 033 sortCriteria = opts.Criteria21 unmodified lines55 ansiProcessor = func(data []byte) (util.Chars, *[]ansiOffset) {56 prevLineAnsiState = lineAnsiState57 trimmed, offsets, newState := extractColor(ustring(data), lineAnsiState, nil)58 lineAnsiState = newState55- return util.ToChars([]byte(trimmed)), offsets59+ return util.ToChars(sbytes(trimmed)), offsets60 }61 } else {62 // When color is disabled but ansi option is given,63 // we simply strip out ANSI codes from the input64 ansiProcessor = func(data []byte) (util.Chars, *[]ansiOffset) {65 trimmed, _, _ := extractColor(ustring(data), nil, nil)62- return util.ToChars([]byte(trimmed)), nil66+ return util.ToChars(sbytes(trimmed)), nil67 }68 }69 }70 38 unmodified lines109 header = append(header, transformed)110 eventBox.Set(EvtHeader, header)111 return false112 }109- item.text, item.colors = ansiProcessor([]byte(transformed))113+ item.text, item.colors = ansiProcessor(sbytes(transformed))114 item.text.TrimTrailingWhitespaces()115 item.text.Index = itemIndex116 item.origText = &data117 itemIndex++278 unmodified linesmodified:src/tokenizer.go+2 added-2 removed
89 unmodified lines90 ret := make([]Token, len(tokens))91 92 prefixLength := begin93 for idx := range tokens {94- chars := util.ToChars([]byte(tokens[idx]))94+ chars := util.ToChars(sbytes(tokens[idx]))95 ret[idx] = Token{&chars, int32(prefixLength)}96 prefixLength += chars.Length()97 }98 return ret87 unmodified lines186 minIdx := 0187 if r.begin == r.end {188 idx := r.begin189 if idx == rangeEllipsis {190- chars := util.ToChars([]byte(joinTokens(tokens)))190+ chars := util.ToChars(sbytes(joinTokens(tokens)))191 parts = append(parts, &chars)192 } else {193 if idx < 0 {194 idx += numTokens + 159 unmodified linesmodified:CHANGELOG.md+4 added-1 removed
1 unmodified line2 =========3 4 0.49.05 ------6+- Performance improvements6-- Ingestion performance improved by around 40%7+ - Ingestion performance improved by 40%8+ - `--ansi` performance improved by 50%9+ - `--with-nth` performance improved by 30%10 - Added two environment variables exported to the child processes11 - `FZF_PREVIEW_LABEL`12 - `FZF_BORDER_LABEL`13 ```sh1962 unmodified lines