Skip to content

refactor: use the built-in max/min to simplify the code#3097

Merged
zzzckck merged 1 commit intobnb-chain:developfrom
cuinix:develop
May 19, 2025
Merged

refactor: use the built-in max/min to simplify the code#3097
zzzckck merged 1 commit intobnb-chain:developfrom
cuinix:develop

Conversation

@cuinix
Copy link
Contributor

@cuinix cuinix commented May 15, 2025

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:

  • add each change in a bullet point here
  • ...

Signed-off-by: cuinix <915115094@qq.com>
@zzzckck zzzckck requested a review from Copilot May 19, 2025 02:11
Copy link
Contributor

Copilot AI left a 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 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 zzzckck merged commit de7207f into bnb-chain:develop May 19, 2025
7 checks passed
@zzzckck
Copy link
Collaborator

zzzckck commented May 19, 2025

thank you

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants