4 ms·
> This for loop is less efficient than clearing a map in one operation For maps with keys that are reflexive with == the Go compiler already optimizes the rang
by martisch 4y ago
> This for loop is less efficient than clearing a map in one operation
For maps with keys that are reflexive with == the Go compiler already optimizes the range loop to a single efficient runtime map clear call: https://go-review.googlesource.com/c/go/+/110055 https://go-review.googlesource.com/c/go/+/110055
- tapirl 4y agoYes, for most cases, the for-loop is as efficient as the proposed "clear" function. I am not sure whether or not this is still true if there are NaN keys in the cleared map.