-
Notifications
You must be signed in to change notification settings - Fork 1.4k
refactor: use strings.Builder to improve performance #18189
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -26,6 +26,7 @@ import ( | |
| "encoding/hex" | ||
| "fmt" | ||
| "io" | ||
| "strings" | ||
|
|
||
| "github.com/erigontech/erigon/common" | ||
| ) | ||
|
|
@@ -59,15 +60,16 @@ func (t *Trie) PrintDiff(t2 *Trie, w io.Writer) { | |
| } | ||
|
|
||
| func (n *FullNode) fstring(ind string) string { | ||
| resp := fmt.Sprintf("full\n%s ", ind) | ||
| var resp strings.Builder | ||
| resp.WriteString(fmt.Sprintf("full\n%s ", ind)) | ||
| for i, node := range &n.Children { | ||
| if node == nil { | ||
| resp += indices[i] + ": <nil> " | ||
| resp.WriteString(indices[i] + ": <nil> ") | ||
| } else { | ||
| resp += indices[i] + ": " + node.fstring(ind+" ") | ||
| resp.WriteString(indices[i] + ": " + node.fstring(ind+" ")) | ||
|
||
| } | ||
| } | ||
| return resp + "\n" + ind + "]" | ||
| return resp.String() + "\n" + ind + "]" | ||
| } | ||
| func (n *FullNode) print(w io.Writer) { | ||
| fmt.Fprintf(w, "f(") | ||
|
|
||
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.
String concatenation (
indices[i] + \": <nil> \") defeats the purpose of usingstrings.Builder. Useresp.WriteString(indices[i])followed byresp.WriteString(\": <nil> \")to avoid intermediate string allocation.