refactor: use the built-in max/min to simplify the code#3097
Merged
zzzckck merged 1 commit intobnb-chain:developfrom May 19, 2025
Merged
refactor: use the built-in max/min to simplify the code#3097zzzckck merged 1 commit intobnb-chain:developfrom
zzzckck merged 1 commit intobnb-chain:developfrom
Conversation
Signed-off-by: cuinix <915115094@qq.com>
buddh0
approved these changes
May 19, 2025
Contributor
There was a problem hiding this comment.
Pull Request Overview
This PR refactors the code in the hexutil and bitutil packages to use built‑in max/min functions, thereby simplifying the logic used for setting boundary indices and byte slice lengths.
- Replaces custom if-conditions with "max" in hexutil JSON and Hex decoding functions.
- Refactors multiple min comparisons in bitutil functions to use the "min" function for cleaner and more concise code.
Reviewed Changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| common/hexutil/json.go | Replaces manual boundary adjustments with the built‑in max function |
| common/hexutil/hexutil.go | Uses the built‑in max function to simplify code in big integer decoding |
| common/bitutil/bitutil.go | Substitutes conditionals for computing the minimum length with the built‑in min function |
Comments suppressed due to low confidence (6)
common/hexutil/json.go:182
- Ensure that the 'max' function is available in your Go environment or imported/defined appropriately, as it may not be available in older Go versions.
start := max(end-bigWordNibbles, 0)
common/hexutil/hexutil.go:150
- Verify that the 'max' function is supported or properly imported in this context, ensuring consistency with the intended Go version.
start := max(end-bigWordNibbles, 0)
common/bitutil/bitutil.go:30
- Confirm that the 'min' function is available or imported appropriately, as its absence in certain Go versions could lead to build issues.
n := min(len(b), len(a))
common/bitutil/bitutil.go:49
- Confirm that the 'min' function is available or imported appropriately, as its absence in certain Go versions could lead to build issues.
n := min(len(b), len(a))
common/bitutil/bitutil.go:68
- Ensure that the 'min' function is defined or imported properly to avoid any potential compatibility issues with the Go version in use.
n := min(len(b), len(a))
common/bitutil/bitutil.go:125
- Ensure that the 'min' function is defined or imported properly to avoid any potential compatibility issues with the Go version in use.
n := min(len(b), len(a))
zzzckck
approved these changes
May 19, 2025
Collaborator
|
thank you |
zzzckck
pushed a commit
that referenced
this pull request
May 19, 2025
galaio
pushed a commit
to galaio/bsc
that referenced
this pull request
May 29, 2025
galaio
pushed a commit
to galaio/bsc
that referenced
this pull request
May 29, 2025
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
use the built-in max/min to simplify the code
Rationale
tell us why we need these changes...
Example
add an example CLI or API response...
Changes
Notable changes: