Skip to content

Optimize cases of clearing maps #832

@breml

Description

@breml

Since merge of 110055 (Issue: go#20138, the clearing of maps (that is, delete all key/values from the map such that is empty) with a for ... range loop has been implemented in the compiler to emit optimized code. So go-critic could detect respective cases and suggest the necessary fix.

Before:

m = map[K]V{}

After:

for k := range m {
    delete(m, k)
}

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions