summaryrefslogtreecommitdiff
path: root/src/util
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/util
parentf7f01d109eb05c7eae82c243b6b6d5c5951ee707 (diff)
downloadfzf-37dc273148df0893053bf5cda0582a23f5c2b2d2.tar.gz
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/util')
-rw-r--r--src/util/util.go10
1 files changed, 10 insertions, 0 deletions
diff --git a/src/util/util.go b/src/util/util.go
index 113fee91..2ebd0f62 100644
--- a/src/util/util.go
+++ b/src/util/util.go
@@ -4,6 +4,7 @@ package util
import "C"
import (
+ "math"
"os"
"os/exec"
"time"
@@ -63,6 +64,15 @@ func Constrain(val int, min int, max int) int {
return val
}
+func AsUint16(val int) uint16 {
+ if val > math.MaxUint16 {
+ return math.MaxUint16
+ } else if val < 0 {
+ return 0
+ }
+ return uint16(val)
+}
+
// DurWithin limits the given time.Duration with the upper and lower bounds
func DurWithin(
val time.Duration, min time.Duration, max time.Duration) time.Duration {