Browse Source

Merge pull request #5405 from gyuho/watch_client

clientv3: preallocate watch streams slice
Xiang Li 9 years ago
parent
commit
54536af135
1 changed files with 1 additions and 1 deletions
  1. 1 1
      clientv3/watch.go

+ 1 - 1
clientv3/watch.go

@@ -520,8 +520,8 @@ func (w *watcher) openWatchClient() (ws pb.Watch_WatchClient, err error) {
 
 
 // resumeWatchers rebuilds every registered watcher on a new client
 // resumeWatchers rebuilds every registered watcher on a new client
 func (w *watcher) resumeWatchers(wc pb.Watch_WatchClient) error {
 func (w *watcher) resumeWatchers(wc pb.Watch_WatchClient) error {
-	streams := []*watcherStream{}
 	w.mu.RLock()
 	w.mu.RLock()
+	streams := make([]*watcherStream, 0, len(w.streams))
 	for _, ws := range w.streams {
 	for _, ws := range w.streams {
 		streams = append(streams, ws)
 		streams = append(streams, ws)
 	}
 	}