Skip to content

Commit d39c158

Browse files
committed
optime: reduce unnecessary copy operations
1 parent 42c3284 commit d39c158

File tree

1 file changed

+6
-9
lines changed

1 file changed

+6
-9
lines changed

ring.go

+6-9
Original file line numberDiff line numberDiff line change
@@ -350,16 +350,13 @@ func (c *ringSharding) newRingShards(
350350
}
351351

352352
func (c *ringSharding) List() []*ringShard {
353-
var list []*ringShard
354-
355353
c.mu.RLock()
356-
if !c.closed {
357-
list = make([]*ringShard, len(c.shards.list))
358-
copy(list, c.shards.list)
359-
}
360-
c.mu.RUnlock()
354+
defer c.mu.RUnlock()
361355

362-
return list
356+
if c.closed {
357+
return nil
358+
}
359+
return c.shards.list
363360
}
364361

365362
func (c *ringSharding) Hash(key string) string {
@@ -810,7 +807,7 @@ func (c *Ring) Watch(ctx context.Context, fn func(*Tx) error, keys ...string) er
810807

811808
for _, key := range keys {
812809
if key != "" {
813-
shard, err := c.sharding.GetByKey(hashtag.Key(key))
810+
shard, err := c.sharding.GetByKey(key)
814811
if err != nil {
815812
return err
816813
}

0 commit comments

Comments
 (0)