Repository navigation
refactor(context): using maps.Clone - #4333
Conversation
|
name old time/op new time/op delta name old alloc/op new alloc/op delta name old allocs/op new allocs/op delta |
|
lol sorry ignore that please (i'm not a maintainer) |
There was a problem hiding this comment.
Pull Request Overview
This PR refactors the Context.Copy() method to use Go's standard library maps.Clone function instead of manually copying map elements. This change simplifies the code by replacing a manual loop-based map copying approach with the built-in utility function.
- Replaced manual map copying logic with
maps.Clone - Added import for the
mapspackage - Removed the manual
makeandforloop for copying theKeysmap
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
| cKeys := c.Keys | ||
| cp.Keys = make(map[any]any, len(cKeys)) | ||
| c.mu.RLock() | ||
| for k, v := range cKeys { | ||
| cp.Keys[k] = v | ||
| } | ||
| cp.Keys = maps.Clone(cKeys) |
There was a problem hiding this comment.
The maps.Clone call should be moved inside the mutex lock section. Currently, cKeys is read outside the lock but maps.Clone is called after acquiring the lock, which could lead to a race condition if c.Keys is modified between reading cKeys and cloning it.
https://go-review.googlesource.com/c/go/+/471400
master