From ca7dc1b6a54c8a4454286ff3400609dc046064dd Mon Sep 17 00:00:00 2001 From: Daisuke Maki Date: Sat, 14 Mar 2015 15:24:38 +0900 Subject: [PATCH] We don't need this globally unique ID stuff This wasn't a distributed system, oops. --- action.go | 4 ++++ buffer.go | 3 +-- line.go | 66 ++++++++++++---------------------------------------- peco_test.go | 20 +++++++++++++++- 4 files changed, 39 insertions(+), 54 deletions(-) diff --git a/action.go b/action.go index fa02315..d7b2350 100644 --- a/action.go +++ b/action.go @@ -206,6 +206,8 @@ func doSelectAll(i *Input, _ termbox.Event) { for x := 0; x < b.Size(); x++ { if l, err := b.LineAt(x); err == nil { i.selection.Add(l) + } else { + i.selection.Remove(l) } } } @@ -295,6 +297,8 @@ func doInvertSelection(i *Input, _ termbox.Event) { for x := 0; x < b.Size(); x++ { if l, err := b.LineAt(x); err == nil { i.selection.Add(l) + } else { + i.selection.Remove(l) } } diff --git a/buffer.go b/buffer.go index ff2e342..18843f1 100644 --- a/buffer.go +++ b/buffer.go @@ -153,10 +153,9 @@ func (rlb *RawLineBuffer) Append(l Line) (Line, error) { tracer.Printf("RawLineBuffer.Append: %s", l.DisplayString()) if rlb.capacity > 0 && len(rlb.lines) > rlb.capacity { diff := len(rlb.lines) - rlb.capacity - // TODO Notify that we're invalidating these lines // Golang's version of array realloc - rlb.lines = append(append([]Line(nil), rlb.lines[diff:]...), l) + rlb.lines = rlb.lines[diff:rlb.capacity:rlb.capacity] } else { rlb.lines = append(rlb.lines, l) } diff --git a/line.go b/line.go index 8a4b1e4..3d5f904 100644 --- a/line.go +++ b/line.go @@ -3,68 +3,32 @@ package peco import ( "regexp" "strings" - "sync" - "time" "github.com/google/btree" ) -const ( - epochOffset = 946684800 - hostIDBits = 16 - serialBits = 12 - serialShift = 16 - timeBits = 36 - timeShift = 28 -) - type idGen struct { - seed uint64 - mutex *sync.Mutex - serialID int64 - timeID int64 - timeout int64 + genCh chan uint64 } -func newIDGen(seed uint64) *idGen { +func newIDGen() *idGen { + ch := make(chan uint64) + go func() { + var i uint64 + for ; ; i++ { + ch <- i + if i >= uint64(1<<63)-1 { + i = 0 + } + } + }() return &idGen{ - seed: seed, - mutex: &sync.Mutex{}, - serialID: 1, - timeID: time.Now().Unix(), + genCh: ch, } } func (ig *idGen) create() uint64 { - ig.mutex.Lock() - defer ig.mutex.Unlock() - - timeID := time.Now().Unix() - serialID := ig.serialID - if ig.timeID == 0 { - ig.timeID = timeID - } - - if ig.timeID == timeID { - serialID++ - } else { - serialID = 1 - } - - if serialID >= (1<