mirror of
https://github.com/junegunn/fzf.git
synced 2025-08-06 07:02:09 -07:00
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:
@@ -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 {
|
||||
|
Reference in New Issue
Block a user