summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChristian Muehlhaeuser <muesli@gmail.com>2019-07-19 06:22:35 +0200
committerJunegunn Choi <junegunn.c@gmail.com>2019-07-19 13:22:35 +0900
commita1260feeed0cc565dfe3cca9927e1f21af7c80ef (patch)
tree86d3d6b279b5f8a2174cfb55bf895482780cc5a1
parent7322504ad07297bf44b6a7e2b8ac7a363928e6d7 (diff)
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
-rw-r--r--src/history.go2
-rw-r--r--src/matcher.go4
-rw-r--r--src/terminal.go2
-rw-r--r--src/tokenizer.go2
-rw-r--r--src/tui/light.go2
-rw-r--r--src/util/chars.go1
6 files changed, 6 insertions, 7 deletions
diff --git a/src/history.go b/src/history.go
index 4aa87fc8..45728d40 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 3c5dec09..69250873 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 58cfbcad..1d379898 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 208d79e9..6485dedc 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 2c2dc004..4ca956c4 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 04a66d7d..e36ab769 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) {