Browse Source

Merge pull request #5115 from gyuho/gc

v3rpc: bytes-key map look-up gc optimization
Xiang Li 9 năm trước cách đây
mục cha
commit
9504df2917
1 tập tin đã thay đổi với 4 bổ sung6 xóa
  1. 4 6
      etcdserver/api/v3rpc/key.go

+ 4 - 6
etcdserver/api/v3rpc/key.go

@@ -185,11 +185,10 @@ func checkRequestDupKeys(reqs []*pb.RequestUnion) error {
 		if preq == nil {
 			continue
 		}
-		key := string(preq.Key)
-		if _, ok := keys[key]; ok {
+		if _, ok := keys[string(preq.Key)]; ok {
 			return rpctypes.ErrDuplicateKey
 		}
-		keys[key] = struct{}{}
+		keys[string(preq.Key)] = struct{}{}
 	}
 
 	// no need to check deletes if no puts; delete overlaps are permitted
@@ -214,13 +213,12 @@ func checkRequestDupKeys(reqs []*pb.RequestUnion) error {
 		if dreq == nil {
 			continue
 		}
-		key := string(dreq.Key)
 		if dreq.RangeEnd == nil {
-			if _, found := keys[key]; found {
+			if _, found := keys[string(dreq.Key)]; found {
 				return rpctypes.ErrDuplicateKey
 			}
 		} else {
-			lo := sort.SearchStrings(sortedKeys, key)
+			lo := sort.SearchStrings(sortedKeys, string(dreq.Key))
 			hi := sort.SearchStrings(sortedKeys, string(dreq.RangeEnd))
 			if lo != hi {
 				// element between lo and hi => overlap