From 659011c1432fc6ea0b1334aaff08302cb2672155 Mon Sep 17 00:00:00 2001 From: Evgenii Stratonikov Date: Sat, 12 Nov 2022 11:05:37 +0300 Subject: [PATCH] [#2048] network/cache: Optimize `ClientCache` 1. Remove a layer of indirection for mutex, `ClientCache` is already used by pointer. 2. Fix duplication of a `AllowExternal` field. Signed-off-by: Evgenii Stratonikov --- pkg/network/cache/client.go | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/pkg/network/cache/client.go b/pkg/network/cache/client.go index c77078eb..3a1edfa0 100644 --- a/pkg/network/cache/client.go +++ b/pkg/network/cache/client.go @@ -13,10 +13,9 @@ type ( // ClientCache is a structure around neofs-sdk-go/client to reuse // already created clients. ClientCache struct { - mu *sync.RWMutex - clients map[string]*multiClient - opts ClientCacheOpts - allowExternal bool + mu sync.RWMutex + clients map[string]*multiClient + opts ClientCacheOpts } ClientCacheOpts struct { @@ -32,17 +31,15 @@ type ( // `opts` are used for new client creation. func NewSDKClientCache(opts ClientCacheOpts) *ClientCache { return &ClientCache{ - mu: new(sync.RWMutex), - clients: make(map[string]*multiClient), - opts: opts, - allowExternal: opts.AllowExternal, + clients: make(map[string]*multiClient), + opts: opts, } } // Get function returns existing client or creates a new one. func (c *ClientCache) Get(info clientcore.NodeInfo) (clientcore.Client, error) { netAddr := info.AddressGroup() - if c.allowExternal { + if c.opts.AllowExternal { netAddr = append(netAddr, info.ExternalAddressGroup()...) } cacheKey := string(info.PublicKey())