Back to UnixNano(), syscall dependency isn't worth a few nanoseconds better performance

This commit is contained in:
Patrick Mylund Nielsen 2015-11-30 15:12:19 -05:00
parent f6cdd07cbb
commit afadf13f9f
1 changed files with 5 additions and 16 deletions

View File

@ -7,7 +7,6 @@ import (
"os"
"runtime"
"sync"
"syscall"
"time"
)
@ -21,9 +20,7 @@ func (item Item) Expired() bool {
if item.Expiration == 0 {
return false
}
var tv syscall.Timeval
syscall.Gettimeofday(&tv)
return tv.Nano() > item.Expiration
return time.Now().UnixNano() > item.Expiration
}
const (
@ -112,9 +109,7 @@ func (c *cache) Get(k string) (interface{}, bool) {
return nil, false
}
if item.Expiration > 0 {
var tv syscall.Timeval
syscall.Gettimeofday(&tv)
if tv.Nano() > item.Expiration {
if time.Now().UnixNano() > item.Expiration {
c.mu.RUnlock()
return nil, false
}
@ -130,9 +125,7 @@ func (c *cache) get(k string) (interface{}, bool) {
}
// "Inlining" of Expired
if item.Expiration > 0 {
var tv syscall.Timeval
syscall.Gettimeofday(&tv)
if tv.Nano() > item.Expiration {
if time.Now().UnixNano() > item.Expiration {
c.mu.RUnlock()
return nil, false
}
@ -890,12 +883,8 @@ type keyAndValue struct {
// Delete all expired items from the cache.
func (c *cache) DeleteExpired() {
var (
evictedItems []keyAndValue
tv syscall.Timeval
)
syscall.Gettimeofday(&tv)
now := tv.Nano()
var evictedItems []keyAndValue
now := time.Now().UnixNano()
c.mu.Lock()
for k, v := range c.items {
// "Inlining" of expired