Don't lock entry when scanning new values to add

pull/6186/head
Jason Wilder 2016-03-31 23:48:24 -06:00
parent fde5576d64
commit fbaa7db54f
1 changed files with 11 additions and 4 deletions

View File

@ -34,13 +34,15 @@ func newEntry() *entry {
// add adds the given values to the entry.
func (e *entry) add(values []Value) {
e.mu.Lock()
defer e.mu.Unlock()
// See if the new values are sorted or contain duplicate timestamps
var prevTime int64
var (
prevTime int64
needSort bool
)
for _, v := range values {
if v.UnixNano() <= prevTime {
e.needSort = true
needSort = true
break
}
prevTime = v.UnixNano()
@ -48,6 +50,10 @@ func (e *entry) add(values []Value) {
// if there are existing values make sure they're all less than the first of
// the new values being added
e.mu.Lock()
if needSort {
e.needSort = needSort
}
if len(e.values) == 0 {
e.values = values
} else {
@ -58,6 +64,7 @@ func (e *entry) add(values []Value) {
}
e.values = append(e.values, values...)
}
e.mu.Unlock()
}
// deduplicate sorts and orders the entry's values. If values are already deduped and