Skip to content

Commit 31a1691

Browse files
authored
Merge pull request #2053 from The127/redundant-map-size
Remove redundant map size
2 parents ef82351 + da3188a commit 31a1691

File tree

12 files changed

+37
-38
lines changed

12 files changed

+37
-38
lines changed

cmd/generate-config/incus_doc.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ func getSortedKeysFromMap[K string, V IterableAny](m map[K]V) []K {
7575

7676
func parse(path string, outputJSONPath string, excludedPaths []string) (*doc, error) {
7777
jsonDoc := &doc{}
78-
docKeys := make(map[string]struct{}, 0)
78+
docKeys := make(map[string]struct{})
7979
projectEntries := make(map[string]any)
8080
err := filepath.Walk(path, func(path string, info os.FileInfo, err error) error {
8181
if err != nil {

cmd/incusd/api_internal.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -836,11 +836,11 @@ func internalImportFromBackup(ctx context.Context, s *state.State, projectName s
836836

837837
// Add root device if needed.
838838
if backupConf.Container.Devices == nil {
839-
backupConf.Container.Devices = make(map[string]map[string]string, 0)
839+
backupConf.Container.Devices = make(map[string]map[string]string)
840840
}
841841

842842
if backupConf.Container.ExpandedDevices == nil {
843-
backupConf.Container.ExpandedDevices = make(map[string]map[string]string, 0)
843+
backupConf.Container.ExpandedDevices = make(map[string]map[string]string)
844844
}
845845

846846
internalImportRootDevicePopulate(instancePoolName, backupConf.Container.Devices, backupConf.Container.ExpandedDevices, profiles)
@@ -930,11 +930,11 @@ func internalImportFromBackup(ctx context.Context, s *state.State, projectName s
930930

931931
// Add root device if needed.
932932
if snap.Devices == nil {
933-
snap.Devices = make(map[string]map[string]string, 0)
933+
snap.Devices = make(map[string]map[string]string)
934934
}
935935

936936
if snap.ExpandedDevices == nil {
937-
snap.ExpandedDevices = make(map[string]map[string]string, 0)
937+
snap.ExpandedDevices = make(map[string]map[string]string)
938938
}
939939

940940
internalImportRootDevicePopulate(instancePoolName, snap.Devices, snap.ExpandedDevices, profiles)

cmd/incusd/api_internal_recover.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -519,11 +519,11 @@ func internalRecoverImportInstance(s *state.State, pool storagePools.Pool, proje
519519

520520
// Add root device if needed.
521521
if poolVol.Container.Devices == nil {
522-
poolVol.Container.Devices = make(map[string]map[string]string, 0)
522+
poolVol.Container.Devices = make(map[string]map[string]string)
523523
}
524524

525525
if poolVol.Container.ExpandedDevices == nil {
526-
poolVol.Container.ExpandedDevices = make(map[string]map[string]string, 0)
526+
poolVol.Container.ExpandedDevices = make(map[string]map[string]string)
527527
}
528528

529529
internalImportRootDevicePopulate(pool.Name(), poolVol.Container.Devices, poolVol.Container.ExpandedDevices, profiles)
@@ -555,11 +555,11 @@ func internalRecoverImportInstanceSnapshot(s *state.State, pool storagePools.Poo
555555

556556
// Add root device if needed.
557557
if snap.Devices == nil {
558-
snap.Devices = make(map[string]map[string]string, 0)
558+
snap.Devices = make(map[string]map[string]string)
559559
}
560560

561561
if snap.ExpandedDevices == nil {
562-
snap.ExpandedDevices = make(map[string]map[string]string, 0)
562+
snap.ExpandedDevices = make(map[string]map[string]string)
563563
}
564564

565565
internalImportRootDevicePopulate(pool.Name(), snap.Devices, snap.ExpandedDevices, profiles)

cmd/incusd/api_internal_test.go

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import (
1111
// Test that an instance with a local root disk device just gets its pool property modified.
1212
func TestInternalImportRootDevicePopulate_LocalDevice(t *testing.T) {
1313
instancePoolName := "test"
14-
localDevices := make(map[string]map[string]string, 0)
14+
localDevices := make(map[string]map[string]string)
1515

1616
localRootDev := map[string]string{
1717
"type": "disk",
@@ -35,8 +35,8 @@ func TestInternalImportRootDevicePopulate_LocalDevice(t *testing.T) {
3535
// modified.
3636
func TestInternalImportRootDevicePopulate_ExpandedDeviceProfileDeviceMismatch(t *testing.T) {
3737
instancePoolName := "test"
38-
localDevices := make(map[string]map[string]string, 0)
39-
expandedDevices := make(map[string]map[string]string, 0)
38+
localDevices := make(map[string]map[string]string)
39+
expandedDevices := make(map[string]map[string]string)
4040

4141
expandedRootDev := map[string]string{
4242
"type": "disk",
@@ -67,8 +67,8 @@ func TestInternalImportRootDevicePopulate_ExpandedDeviceProfileDeviceMismatch(t
6767
// disk device.
6868
func TestInternalImportRootDevicePopulate_ExpandedDeviceProfileDeviceMatch(t *testing.T) {
6969
instancePoolName := "test"
70-
localDevices := make(map[string]map[string]string, 0)
71-
expandedDevices := make(map[string]map[string]string, 0)
70+
localDevices := make(map[string]map[string]string)
71+
expandedDevices := make(map[string]map[string]string)
7272

7373
expandedRootDev := map[string]string{
7474
"type": "disk",
@@ -83,7 +83,7 @@ func TestInternalImportRootDevicePopulate_ExpandedDeviceProfileDeviceMatch(t *te
8383
{
8484
Name: "default",
8585
ProfilePut: api.ProfilePut{
86-
Devices: make(map[string]map[string]string, 0),
86+
Devices: make(map[string]map[string]string),
8787
},
8888
},
8989
}
@@ -104,8 +104,8 @@ func TestInternalImportRootDevicePopulate_ExpandedDeviceProfileDeviceMatch(t *te
104104
// target pool that the old expanded root device is added as a local root disk device (with the pool modified).
105105
func TestInternalImportRootDevicePopulate_ExpandedDeviceProfileDevicePoolMismatch(t *testing.T) {
106106
instancePoolName := "test"
107-
localDevices := make(map[string]map[string]string, 0)
108-
expandedDevices := make(map[string]map[string]string, 0)
107+
localDevices := make(map[string]map[string]string)
108+
expandedDevices := make(map[string]map[string]string)
109109

110110
expandedRootDev := map[string]string{
111111
"type": "disk",
@@ -120,7 +120,7 @@ func TestInternalImportRootDevicePopulate_ExpandedDeviceProfileDevicePoolMismatc
120120
{
121121
Name: "default",
122122
ProfilePut: api.ProfilePut{
123-
Devices: make(map[string]map[string]string, 0),
123+
Devices: make(map[string]map[string]string),
124124
},
125125
},
126126
}
@@ -144,7 +144,7 @@ func TestInternalImportRootDevicePopulate_ExpandedDeviceProfileDevicePoolMismatc
144144
// device is added using the target pool.
145145
func TestInternalImportRootDevicePopulate_NoExistingRootDiskDevice(t *testing.T) {
146146
instancePoolName := "test"
147-
localDevices := make(map[string]map[string]string, 0)
147+
localDevices := make(map[string]map[string]string)
148148

149149
internalImportRootDevicePopulate(instancePoolName, localDevices, nil, nil)
150150

@@ -158,7 +158,7 @@ func TestInternalImportRootDevicePopulate_NoExistingRootDiskDevice(t *testing.T)
158158
// disk device is added under an automatically generated name.
159159
func TestInternalImportRootDevicePopulate_NoExistingRootDiskDeviceNameConflict(t *testing.T) {
160160
instancePoolName := "test"
161-
localDevices := make(map[string]map[string]string, 0)
161+
localDevices := make(map[string]map[string]string)
162162

163163
localConflictingRootDev := map[string]string{
164164
"type": "nic",

cmd/incusd/instance.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -628,7 +628,7 @@ func pruneExpiredAndAutoCreateInstanceSnapshotsTask(d *Daemon) (task.Func, task.
628628

629629
if len(expiredSnaps) > 0 {
630630
expiredSnapshots := make([]dbCluster.Instance, 0, len(expiredSnaps))
631-
parents := make(map[string]*dbCluster.Instance, 0)
631+
parents := make(map[string]*dbCluster.Instance)
632632

633633
// Enrich expired snapshot list with info from parent (opportunistically loading
634634
// the parent info from the DB if not already loaded).

cmd/incusd/patches.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -809,7 +809,7 @@ func patchStorageRenameCustomISOBlockVolumes(_ string, d *Daemon) error {
809809
}
810810

811811
volTypeCustom := db.StoragePoolVolumeTypeCustom
812-
customPoolVolumes := make(map[string][]*db.StorageVolume, 0)
812+
customPoolVolumes := make(map[string][]*db.StorageVolume)
813813

814814
err = s.DB.Cluster.Transaction(s.ShutdownCtx, func(ctx context.Context, tx *db.ClusterTx) error {
815815
for _, pool := range pools {
@@ -898,7 +898,7 @@ func patchZfsSetContentTypeUserProperty(_ string, d *Daemon) error {
898898
}
899899

900900
volTypeCustom := db.StoragePoolVolumeTypeCustom
901-
customPoolVolumes := make(map[string][]*db.StorageVolume, 0)
901+
customPoolVolumes := make(map[string][]*db.StorageVolume)
902902

903903
err = s.DB.Cluster.Transaction(s.ShutdownCtx, func(ctx context.Context, tx *db.ClusterTx) error {
904904
for _, pool := range pools {
@@ -995,8 +995,8 @@ func patchStorageZfsUnsetInvalidBlockSettings(_ string, d *Daemon) error {
995995
volTypeCustom := db.StoragePoolVolumeTypeCustom
996996
volTypeVM := db.StoragePoolVolumeTypeVM
997997

998-
poolIDNameMap := make(map[int64]string, 0)
999-
poolVolumes := make(map[int64][]*db.StorageVolume, 0)
998+
poolIDNameMap := make(map[int64]string)
999+
poolVolumes := make(map[int64][]*db.StorageVolume)
10001000

10011001
err = s.DB.Cluster.Transaction(s.ShutdownCtx, func(ctx context.Context, tx *db.ClusterTx) error {
10021002
for _, pool := range pools {
@@ -1113,8 +1113,8 @@ func patchStorageZfsUnsetInvalidBlockSettingsV2(_ string, d *Daemon) error {
11131113
volTypeCustom := db.StoragePoolVolumeTypeCustom
11141114
volTypeVM := db.StoragePoolVolumeTypeVM
11151115

1116-
poolIDNameMap := make(map[int64]string, 0)
1117-
poolVolumes := make(map[int64][]*db.StorageVolume, 0)
1116+
poolIDNameMap := make(map[int64]string)
1117+
poolVolumes := make(map[int64][]*db.StorageVolume)
11181118

11191119
err = s.DB.Cluster.Transaction(s.ShutdownCtx, func(ctx context.Context, tx *db.ClusterTx) error {
11201120
for _, pool := range pools {

cmd/lxc-to-incus/main_migrate_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -225,7 +225,7 @@ func TestConvertNetworkConfig(t *testing.T) {
225225
require.NoError(t, err)
226226
}
227227

228-
devices := make(map[string]map[string]string, 0)
228+
devices := make(map[string]map[string]string)
229229
err = convertNetworkConfig(c, devices)
230230
if tt.shouldFail {
231231
require.EqualError(t, err, tt.expectedError)
@@ -328,7 +328,7 @@ func TestConvertStorageConfig(t *testing.T) {
328328

329329
for i, tt := range tests {
330330
log.Printf("Running test #%d: %s", i, tt.name)
331-
devices := make(map[string]map[string]string, 0)
331+
devices := make(map[string]map[string]string)
332332
err := convertStorageConfig(tt.config, devices)
333333
if tt.shouldFail {
334334
require.EqualError(t, err, tt.expectedError)

internal/server/db/cluster/update.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4457,7 +4457,7 @@ FROM storage_volumes
44574457

44584458
// Duplicate each volume row across all nodes, and keep track of the
44594459
// new volume IDs that we've inserted.
4460-
created := make(map[int][]int64, 0) // Existing volume ID to new volumes IDs.
4460+
created := make(map[int][]int64) // Existing volume ID to new volumes IDs.
44614461
columns := []string{"name", "storage_pool_id", "node_id", "type", "description"}
44624462
for _, volume := range volumes {
44634463
for _, nodeID := range nodeIDs {

internal/server/firewall/drivers/drivers_nftables.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -241,7 +241,7 @@ func (d Nftables) networkSetupForwardingPolicy(networkName string, ip4Allow *boo
241241
// If srcIP is non-nil then SNAT is used with the specified address, otherwise MASQUERADE mode is used.
242242
// Append mode is always on and so the append argument is ignored.
243243
func (d Nftables) networkSetupOutboundNAT(networkName string, SNATV4 *SNATOpts, SNATV6 *SNATOpts) error {
244-
rules := make(map[string]*SNATOpts, 0)
244+
rules := make(map[string]*SNATOpts)
245245

246246
tplFields := map[string]any{
247247
"namespace": nftablesNamespace,

internal/server/network/acl/acl_ovn.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,7 @@ func OVNEnsureACLs(s *state.State, l logger.Logger, client *ovn.NB, aclProjectNa
195195
// We will create port groups (without ACL rules) for any missing referenced ACL OVN port groups so that
196196
// when we add the rules for the new ACL port groups this doesn't trigger an OVN log error about missing
197197
// port groups.
198-
referencedACLs := make(map[string]struct{}, 0)
198+
referencedACLs := make(map[string]struct{})
199199
for _, aclStatus := range createACLPortGroups {
200200
ovnAddReferencedACLs(aclStatus.aclInfo, referencedACLs)
201201
}
@@ -887,7 +887,7 @@ func OVNPortGroupDeleteIfUnused(s *state.State, l logger.Logger, client *ovn.NB,
887887

888888
// Filter project port group list by ACL related ones, and store them in a map keyed by port group name.
889889
// This contains the initial candidates for removal. But any found to be in use will be removed from list.
890-
removeACLPortGroups := make(map[ovn.OVNPortGroup]struct{}, 0)
890+
removeACLPortGroups := make(map[ovn.OVNPortGroup]struct{})
891891
for _, portGroup := range portGroups {
892892
// If port group is related to an ACL and is not related to one of keepACLs, then add it as a
893893
// candidate for removal.
@@ -905,7 +905,7 @@ func OVNPortGroupDeleteIfUnused(s *state.State, l logger.Logger, client *ovn.NB,
905905
}
906906

907907
// Map to record ACLs being referenced by other ACLs. Need to check later if they are in use with OVN ACLs.
908-
aclUsedACLS := make(map[string][]string, 0)
908+
aclUsedACLS := make(map[string][]string)
909909

910910
// Find all ACLs that are either directly referred to by OVN entities (networks, instance/profile NICs)
911911
// or indirectly by being referred to by a ruleset of another ACL that is itself in use by OVN entities.

internal/server/network/driver_common.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -193,8 +193,7 @@ func (n *common) validateZoneNames(config map[string]string) error {
193193
return fmt.Errorf("Invalid %q must contain only single DNS zone name", keyName)
194194
}
195195

196-
zoneProjectsUsed := make(map[string]struct{}, 0)
197-
196+
zoneProjectsUsed := make(map[string]struct{})
198197
for _, keyZoneName := range keyZoneNames {
199198
zoneProjectName, found := zoneProjects[keyZoneName]
200199
if !found {

internal/server/network/ovn/ovn_nb_actions.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3909,8 +3909,8 @@ func (o *NB) CreateLogicalRouterPeering(ctx context.Context, opts OVNRouterPeeri
39093909
}
39103910

39113911
// Will use the first IP from each family of the router port interfaces.
3912-
localRouterGatewayIPs := make(map[uint]net.IP, 0)
3913-
targetRouterGatewayIPs := make(map[uint]net.IP, 0)
3912+
localRouterGatewayIPs := make(map[uint]net.IP)
3913+
targetRouterGatewayIPs := make(map[uint]net.IP)
39143914

39153915
// Create the local router port.
39163916
localPeerName := string(opts.TargetRouterPort)

0 commit comments

Comments
 (0)