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
This commit is contained in:
Junegunn Choi
2016-08-19 02:39:32 +09:00
parent f7f01d109e
commit 37dc273148
19 changed files with 236 additions and 570 deletions

View File

@@ -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 {