Skip to content

Commit b042f91

Browse files
authored
refactor: use maps.Copy to simplify the code (#5321)
Signed-off-by: dulanting <[email protected]>
1 parent 2fef6c4 commit b042f91

File tree

2 files changed

+5
-9
lines changed

2 files changed

+5
-9
lines changed

common/configtx/update.go

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ SPDX-License-Identifier: Apache-2.0
77
package configtx
88

99
import (
10+
"maps"
1011
"strings"
1112

1213
cb "github.com/hyperledger/fabric-protos-go-apiv2/common"
@@ -192,12 +193,8 @@ func (vi *ValidatorImpl) policyForItem(item comparable) (policies.Policy, bool)
192193
// computeUpdateResult takes a configMap generated by an update and produces a new configMap overlaying it onto the old config
193194
func (vi *ValidatorImpl) computeUpdateResult(updatedConfig map[string]comparable) map[string]comparable {
194195
newConfigMap := make(map[string]comparable)
195-
for key, value := range vi.configMap {
196-
newConfigMap[key] = value
197-
}
196+
maps.Copy(newConfigMap, vi.configMap)
198197

199-
for key, value := range updatedConfig {
200-
newConfigMap[key] = value
201-
}
198+
maps.Copy(newConfigMap, updatedConfig)
202199
return newConfigMap
203200
}

core/ledger/kvledger/txmgmt/statedb/statecouchdb/couchdb.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import (
1515
"fmt"
1616
"io"
1717
"log"
18+
"maps"
1819
"mime"
1920
"mime/multipart"
2021
"net/http"
@@ -634,9 +635,7 @@ func createAttachmentPart(couchDoc *couchDoc) (bytes.Buffer, string, error) {
634635
}
635636

636637
// add all key/values to the attachmentJSONMap
637-
for jsonKey, jsonValue := range genericMap {
638-
attachmentJSONMap[jsonKey] = jsonValue
639-
}
638+
maps.Copy(attachmentJSONMap, genericMap)
640639

641640
}
642641

0 commit comments

Comments
 (0)