From 7ec9c97e46ebc555379d4a95b13a5d8748a4dc16 Mon Sep 17 00:00:00 2001 From: Matt Jaffee Date: Mon, 2 Jul 2018 08:29:37 -0500 Subject: [PATCH] fixup nopAttrStore. Methods no longer take pointer receiver, and NewNopAttrStore always returns a reference to the same global object (which is no longer exported). --- attr.go | 44 +++++++++++++------------------------------- field.go | 2 +- holder.go | 2 +- index.go | 4 ++-- 4 files changed, 17 insertions(+), 35 deletions(-) diff --git a/attr.go b/attr.go index 34d14a280..628613172 100644 --- a/attr.go +++ b/attr.go @@ -42,57 +42,39 @@ type AttrStore interface { BlockData(i uint64) (map[uint64]map[string]interface{}, error) } -func init() { - NopAttrStore = &nopAttrStore{} -} +// nopStore represents an AttrStore that doesn't do anything. +var nopStore AttrStore = nopAttrStore{} -// NopAttrStore represents an AttrStore that doesn't do anything. -var NopAttrStore AttrStore - -func NewNopAttrStore(string) AttrStore { - return &nopAttrStore{} -} +// newNopAttrStore returns an attr store which does nothing. It returns a global +// object to avoid unecessary allocations. +func newNopAttrStore(string) AttrStore { return nopStore } // nopAttrStore represents a no-op implementation of the AttrStore interface. type nopAttrStore struct{} // Path is a no-op implementation of AttrStore Path method. -func (s *nopAttrStore) Path() string { return "" } +func (s nopAttrStore) Path() string { return "" } // Open is a no-op implementation of AttrStore Open method. -func (s *nopAttrStore) Open() error { - return nil -} +func (s nopAttrStore) Open() error { return nil } // Close is a no-op implementation of AttrStore Close method. -func (s *nopAttrStore) Close() error { - return nil -} +func (s nopAttrStore) Close() error { return nil } // Attrs is a no-op implementation of AttrStore Attrs method. -func (s *nopAttrStore) Attrs(id uint64) (m map[string]interface{}, err error) { - return nil, nil -} +func (s nopAttrStore) Attrs(id uint64) (m map[string]interface{}, err error) { return nil, nil } // SetAttrs is a no-op implementation of AttrStore SetAttrs method. -func (s *nopAttrStore) SetAttrs(id uint64, m map[string]interface{}) error { - return nil -} +func (s nopAttrStore) SetAttrs(id uint64, m map[string]interface{}) error { return nil } // SetBulkAttrs is a no-op implementation of AttrStore SetBulkAttrs method. -func (s *nopAttrStore) SetBulkAttrs(m map[uint64]map[string]interface{}) error { - return nil -} +func (s nopAttrStore) SetBulkAttrs(m map[uint64]map[string]interface{}) error { return nil } // Blocks is a no-op implementation of AttrStore Blocks method. -func (s *nopAttrStore) Blocks() ([]AttrBlock, error) { - return nil, nil -} +func (s nopAttrStore) Blocks() ([]AttrBlock, error) { return nil, nil } // BlockData is a no-op implementation of AttrStore BlockData method. -func (s *nopAttrStore) BlockData(i uint64) (map[uint64]map[string]interface{}, error) { - return nil, nil -} +func (s nopAttrStore) BlockData(i uint64) (map[uint64]map[string]interface{}, error) { return nil, nil } // AttrBlock represents a checksummed block of the attribute store. type AttrBlock struct { diff --git a/field.go b/field.go index 42f607ff9..ed8d1811b 100644 --- a/field.go +++ b/field.go @@ -133,7 +133,7 @@ func NewField(path, index, name string, options FieldOptions) (*Field, error) { views: make(map[string]*View), - rowAttrStore: NopAttrStore, + rowAttrStore: nopStore, broadcaster: NopBroadcaster, Stats: NopStatsClient, diff --git a/holder.go b/holder.go index 0141d365e..e4462519b 100644 --- a/holder.go +++ b/holder.go @@ -81,7 +81,7 @@ func NewHolder() *Holder { Broadcaster: NopBroadcaster, Stats: NopStatsClient, - NewAttrStore: NewNopAttrStore, + NewAttrStore: newNopAttrStore, CacheFlushInterval: defaultCacheFlushInterval, diff --git a/index.go b/index.go index ae6141b90..79ffd69c0 100644 --- a/index.go +++ b/index.go @@ -66,8 +66,8 @@ func NewIndex(path, name string) (*Index, error) { remoteMaxShard: 0, - NewAttrStore: NewNopAttrStore, - columnAttrStore: NopAttrStore, + NewAttrStore: newNopAttrStore, + columnAttrStore: nopStore, broadcaster: NopBroadcaster, Stats: NopStatsClient,