-
Notifications
You must be signed in to change notification settings - Fork 187
fix:remove the duplicate code #81
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
|
@valyala I hope you can take a lokk at it sometime |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR removes duplicate initialization code and simplifies atomic operations in the bucket Reset method. The changes eliminate redundant map initialization and replace atomic store operations with direct assignments under lock protection.
- Removes duplicate
b.m = make(map[uint64]uint64)initialization in bucket Init method - Replaces atomic store operations with direct assignments in Reset method since they occur under mutex protection
| atomic.StoreUint64(&b.misses, 0) | ||
| atomic.StoreUint64(&b.collisions, 0) | ||
| atomic.StoreUint64(&b.corruptions, 0) | ||
| b.getCalls = 0 |
Copilot
AI
Jul 27, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Direct assignment to b.getCalls may cause race conditions if other goroutines read this field concurrently without holding the mutex. If getCalls is accessed outside the mutex elsewhere in the code, atomic operations should be retained.
| atomic.StoreUint64(&b.collisions, 0) | ||
| atomic.StoreUint64(&b.corruptions, 0) | ||
| b.getCalls = 0 | ||
| b.setCalls = 0 |
Copilot
AI
Jul 27, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Direct assignment to b.setCalls may cause race conditions if other goroutines read this field concurrently without holding the mutex. If setCalls is accessed outside the mutex elsewhere in the code, atomic operations should be retained.
| atomic.StoreUint64(&b.corruptions, 0) | ||
| b.getCalls = 0 | ||
| b.setCalls = 0 | ||
| b.misses = 0 |
Copilot
AI
Jul 27, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Direct assignment to b.misses may cause race conditions if other goroutines read this field concurrently without holding the mutex. If misses is accessed outside the mutex elsewhere in the code, atomic operations should be retained.
| b.getCalls = 0 | ||
| b.setCalls = 0 | ||
| b.misses = 0 | ||
| b.collisions = 0 |
Copilot
AI
Jul 27, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Direct assignment to b.collisions may cause race conditions if other goroutines read this field concurrently without holding the mutex. If collisions is accessed outside the mutex elsewhere in the code, atomic operations should be retained.
| b.collisions = 0 | |
| atomic.StoreUint64(&b.collisions, 0) |
| b.setCalls = 0 | ||
| b.misses = 0 | ||
| b.collisions = 0 | ||
| b.corruptions = 0 |
Copilot
AI
Jul 27, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Direct assignment to b.corruptions may cause race conditions if other goroutines read this field concurrently without holding the mutex. If corruptions is accessed outside the mutex elsewhere in the code, atomic operations should be retained.
| b.corruptions = 0 | |
| atomic.StoreUint64(&b.corruptions, 0) |
1.Remove the duplicate code 'b.m = make(map[uint64]uint64)'
2.Because of the protection of the lock, you can operate without using atoms