From a1260feeed0cc565dfe3cca9927e1f21af7c80ef Mon Sep 17 00:00:00 2001 From: Christian Muehlhaeuser Date: Fri, 19 Jul 2019 06:22:35 +0200 Subject: [PATCH] Code cleanup (#1640) - Replaced time.Now().Sub() with time.Since() - Replaced unnecessary string/byte slice conversions - Removed obsolete return and value assignment in range loop --- src/history.go | 2 +- src/matcher.go | 4 ++-- src/terminal.go | 2 +- src/tokenizer.go | 2 +- src/tui/light.go | 2 +- src/util/chars.go | 1 - 6 files changed, 6 insertions(+), 7 deletions(-) diff --git a/src/history.go b/src/history.go index 4aa87fc..45728d4 100644 --- a/src/history.go +++ b/src/history.go @@ -59,7 +59,7 @@ func (h *History) append(line string) error { lines := append(h.lines[:len(h.lines)-1], line) if len(lines) > h.maxSize { - lines = lines[len(lines)-h.maxSize : len(lines)] + lines = lines[len(lines)-h.maxSize:] } h.lines = append(lines, "") return ioutil.WriteFile(h.path, []byte(strings.Join(h.lines, "\n")), 0600) diff --git a/src/matcher.go b/src/matcher.go index 3c5dec0..6925087 100644 --- a/src/matcher.go +++ b/src/matcher.go @@ -207,13 +207,13 @@ func (m *Matcher) scan(request MatchRequest) (*Merger, bool) { return nil, wait() } - if time.Now().Sub(startedAt) > progressMinDuration { + if time.Since(startedAt) > progressMinDuration { m.eventBox.Set(EvtSearchProgress, float32(count)/float32(numChunks)) } } partialResults := make([][]Result, numSlices) - for _ = range slices { + for range slices { partialResult := <-resultChan partialResults[partialResult.index] = partialResult.matches } diff --git a/src/terminal.go b/src/terminal.go index 58cfbca..1d37989 100644 --- a/src/terminal.go +++ b/src/terminal.go @@ -1532,7 +1532,7 @@ func (t *Terminal) Loop() { cmd.Wait() finishChan <- true if out.Len() > 0 || !<-updateChan { - t.reqBox.Set(reqPreviewDisplay, string(out.Bytes())) + t.reqBox.Set(reqPreviewDisplay, out.String()) } } else { t.reqBox.Set(reqPreviewDisplay, "") diff --git a/src/tokenizer.go b/src/tokenizer.go index 208d79e..6485ded 100644 --- a/src/tokenizer.go +++ b/src/tokenizer.go @@ -238,7 +238,7 @@ func Transform(tokens []Token, withNth []Range) []Token { for _, part := range parts { output.WriteString(part.ToString()) } - merged = util.ToChars([]byte(output.String())) + merged = util.ToChars(output.Bytes()) } var prefixLength int32 diff --git a/src/tui/light.go b/src/tui/light.go index 2c2dc00..4ca956c 100644 --- a/src/tui/light.go +++ b/src/tui/light.go @@ -547,7 +547,7 @@ func (r *LightRenderer) mouseSequence(sz *int) Event { r.prevDownTime = now } else { if len(r.clickY) > 1 && r.clickY[0] == r.clickY[1] && - time.Now().Sub(r.prevDownTime) < doubleClickDuration { + time.Since(r.prevDownTime) < doubleClickDuration { double = true } } diff --git a/src/util/chars.go b/src/util/chars.go index 04a66d7..e36ab76 100644 --- a/src/util/chars.go +++ b/src/util/chars.go @@ -169,7 +169,6 @@ func (chars *Chars) CopyRunes(dest []rune) { for idx, b := range chars.slice[:len(dest)] { dest[idx] = rune(b) } - return } func (chars *Chars) Prepend(prefix string) {