-
Notifications
You must be signed in to change notification settings - Fork 275
refactor: use the built-in max/min to simplify the code #1835
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
Conversation
Signed-off-by: jingchanglu <[email protected]>
WalkthroughThe calculation of Changes
Suggested reviewers
Poem
✨ Finishing Touches
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
SupportNeed help? Create a ticket on our support page for assistance with any issues or questions. 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.
Actionable comments posted: 0
🧹 Nitpick comments (1)
x/cronos/rpc/api.go (1)
282-284: Consider an explicitint64literal for constant1
max(blockNumber-1, 1)relies on type-inference to convert the untyped constant toint64. While valid, an explicit cast avoids the (unlikely) chance of a future refactor introducing a mixed-type call that fails compilation.- contextHeight := max(blockNumber-1, 1) + contextHeight := max(blockNumber-1, int64(1))
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (1)
x/cronos/rpc/api.go(1 hunks)
🧰 Additional context used
🧠 Learnings (2)
📓 Common learnings
Learnt from: yihuang
PR: crypto-org-chain/cronos#1618
File: memiavl/db_test.go:193-194
Timestamp: 2024-10-04T16:08:45.617Z
Learning: In Go version 1.21 and later, the `max` function is defined and available.
Learnt from: yihuang
PR: crypto-org-chain/cronos#1618
File: memiavl/db_test.go:193-194
Timestamp: 2024-10-08T19:00:42.142Z
Learning: In Go version 1.21 and later, the `max` function is defined and available.
x/cronos/rpc/api.go (2)
Learnt from: yihuang
PR: crypto-org-chain/cronos#1618
File: memiavl/db_test.go:193-194
Timestamp: 2024-10-04T16:08:45.617Z
Learning: In Go version 1.21 and later, the `max` function is defined and available.
Learnt from: yihuang
PR: crypto-org-chain/cronos#1618
File: memiavl/db_test.go:193-194
Timestamp: 2024-10-08T19:00:42.142Z
Learning: In Go version 1.21 and later, the `max` function is defined and available.
🔇 Additional comments (2)
x/cronos/rpc/api.go (2)
282-284: Concise refactor looks goodReplacing the conditional with the built-in
maxcleans the intent and drops two lines of boilerplate.
282-284: Go toolchain version meets requirement
Confirmed that go.mod specifies Go 1.23.3, which includes the built-in max function from Go 1.21 onwards. No changes needed.
|
Hi Jing Thank you for submitting the PR but I will close it as it does not bring significant improvement in the code. |
👮🏻👮🏻👮🏻 !!!! REFERENCE THE PROBLEM YOUR ARE SOLVING IN THE PR TITLE AND DESCRIBE YOUR SOLUTION HERE !!!! DO NOT FORGET !!!! 👮🏻👮🏻👮🏻
PR Checklist:
make)make test)go fmt)golangci-lint run)go list -json -m all | nancy sleuth)Thank you for your code, it's appreciated! :)
Inspired by #1777 and I have checked all the replaceable case.
Summary by CodeRabbit