-
Notifications
You must be signed in to change notification settings - Fork 107
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
chore(primitives): minor optimization for PowerOfTwo
functions
#2081
base: main
Are you sure you want to change the base?
Conversation
WalkthroughThe changes involve modifications to the Changes
Poem
Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media? 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
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.
@@ -24,7 +24,7 @@ package pow | |||
// | |||
//nolint:mnd // todo fix. | |||
func PrevPowerOfTwo[U64T ~uint64](u U64T) U64T { | |||
if u == 0 { | |||
if u <= 1 { |
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.
🧹 Nitpick (assertive)
LGTM! Consider updating the function documentation.
The change from if u == 0
to if u <= 1
is a good optimization. It correctly handles both edge cases (0 and 1) without affecting the function's behavior for other inputs.
Consider updating the function documentation to reflect this change. For example:
// PrevPowerOfTwo returns the previous power of 2 for the given input.
// For inputs 0 and 1, it returns 1.
@@ -40,7 +40,7 @@ | |||
// | |||
//nolint:mnd // todo fix. | |||
func NextPowerOfTwo[U64T ~uint64](u U64T) U64T { | |||
if u == 0 { | |||
if u <= 1 { |
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.
🧹 Nitpick (assertive)
💡 Codebase verification
Found multiple instances of //nolint:mnd
. Recommend a dedicated effort to address these directives.
🔗 Analysis chain
LGTM! Consider documentation updates and addressing the TODO.
The change from if u == 0
to if u <= 1
is a good optimization. It correctly handles both edge cases (0 and 1) without affecting the function's behavior for other inputs.
- Consider updating the function documentation to reflect this change. For example:
// NextPowerOfTwo returns the next power of 2 for the given input.
// For inputs 0 and 1, it returns 1.
// Panics if the next power of 2 would overflow uint64.
- There's a TODO comment to fix the
nolint:mnd
directive. Consider addressing this in a future PR or explaining why it's needed if it can't be removed.
To ensure the nolint:mnd
directive is still necessary, let's check if it's used elsewhere in the codebase:
🏁 Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash
# Description: Check usage of nolint:mnd directive in the codebase
# Test: Search for nolint:mnd usage
rg --type go "nolint:mnd"
Length of output: 5245
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #2081 +/- ##
=======================================
Coverage 22.23% 22.23%
=======================================
Files 356 356
Lines 16022 16022
Branches 12 12
=======================================
Hits 3563 3563
Misses 12306 12306
Partials 153 153
|
Summary by CodeRabbit