Skip to content
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

perf: use strings.Builder #1571

Open
wants to merge 3 commits into
base: develop
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 7 additions & 5 deletions bridge-history-api/internal/utils/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -172,13 +172,15 @@ func GetBlocksInRange(ctx context.Context, cli *ethclient.Client, start, end uin

// ConvertBigIntArrayToString convert the big int array to string
func ConvertBigIntArrayToString(array []*big.Int) string {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can you add unit test for your changes?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I only modified the internal structure of the function and ran the TestConvertBigIntArrayToString test. The result passed successfully.

stringArray := make([]string, len(array))
var sb strings.Builder
sb.Grow(len(array) * 22)
for i, num := range array {
stringArray[i] = num.String()
if i > 0 {
sb.WriteString(", ")
}
sb.WriteString(num.String())
}

result := strings.Join(stringArray, ", ")
return result
return sb.String()
}

// ConvertStringToStringArray takes a string with values separated by commas and returns a slice of strings
Expand Down