Skip to content

Commit

Permalink
storage: make putm/delm a set with empty value
Browse files Browse the repository at this point in the history
This cleans the code, and reduces the allocation space.
  • Loading branch information
yichengq committed Nov 4, 2015
1 parent 6dbfc21 commit c8e622f
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions storage/watchable_store.go
Original file line number Diff line number Diff line change
Expand Up @@ -304,26 +304,26 @@ func (s *watchableStore) notify(rev int64, ev storagepb.Event) {

type ongoingTx struct {
// keys put/deleted in the ongoing txn
putm map[string]bool
delm map[string]bool
putm map[string]struct{}
delm map[string]struct{}
}

func newOngoingTx() *ongoingTx {
return &ongoingTx{
putm: make(map[string]bool),
delm: make(map[string]bool),
putm: make(map[string]struct{}),
delm: make(map[string]struct{}),
}
}

func (tx *ongoingTx) put(k string) {
tx.putm[k] = true
tx.putm[k] = struct{}{}
if _, ok := tx.delm[k]; ok {
delete(tx.delm, k)
}
}

func (tx *ongoingTx) del(k string) {
tx.delm[k] = true
tx.delm[k] = struct{}{}
if _, ok := tx.putm[k]; ok {
delete(tx.putm, k)
}
Expand Down

0 comments on commit c8e622f

Please sign in to comment.