Skip to content

Commit 35ce9e8

Browse files
s7v7nislandsjagdeep sidhu
authored andcommitted
core/asm: use strings.Builder and fix godoc issues (ethereum#24861)
1 parent 907c0fa commit 35ce9e8

File tree

3 files changed

+15
-15
lines changed

3 files changed

+15
-15
lines changed

core/asm/asm.go

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
// You should have received a copy of the GNU Lesser General Public License
1515
// along with the go-ethereum library. If not, see <http://www.gnu.org/licenses/>.
1616

17-
// Provides support for dealing with EVM assembly instructions (e.g., disassembling them).
17+
// Package asm provides support for dealing with EVM assembly instructions (e.g., disassembling them).
1818
package asm
1919

2020
import (
@@ -34,14 +34,14 @@ type instructionIterator struct {
3434
started bool
3535
}
3636

37-
// Create a new instruction iterator.
37+
// NewInstructionIterator create a new instruction iterator.
3838
func NewInstructionIterator(code []byte) *instructionIterator {
3939
it := new(instructionIterator)
4040
it.code = code
4141
return it
4242
}
4343

44-
// Returns true if there is a next instruction and moves on.
44+
// Next returns true if there is a next instruction and moves on.
4545
func (it *instructionIterator) Next() bool {
4646
if it.error != nil || uint64(len(it.code)) <= it.pc {
4747
// We previously reached an error or the end.
@@ -79,27 +79,27 @@ func (it *instructionIterator) Next() bool {
7979
return true
8080
}
8181

82-
// Returns any error that may have been encountered.
82+
// Error returns any error that may have been encountered.
8383
func (it *instructionIterator) Error() error {
8484
return it.error
8585
}
8686

87-
// Returns the PC of the current instruction.
87+
// PC returns the PC of the current instruction.
8888
func (it *instructionIterator) PC() uint64 {
8989
return it.pc
9090
}
9191

92-
// Returns the opcode of the current instruction.
92+
// Op returns the opcode of the current instruction.
9393
func (it *instructionIterator) Op() vm.OpCode {
9494
return it.op
9595
}
9696

97-
// Returns the argument of the current instruction.
97+
// Arg returns the argument of the current instruction.
9898
func (it *instructionIterator) Arg() []byte {
9999
return it.arg
100100
}
101101

102-
// Pretty-print all disassembled EVM instructions to stdout.
102+
// PrintDisassembled pretty-print all disassembled EVM instructions to stdout.
103103
func PrintDisassembled(code string) error {
104104
script, err := hex.DecodeString(code)
105105
if err != nil {
@@ -117,7 +117,7 @@ func PrintDisassembled(code string) error {
117117
return it.Error()
118118
}
119119

120-
// Return all disassembled EVM instructions in human-readable format.
120+
// Disassemble returns all disassembled EVM instructions in human-readable format.
121121
func Disassemble(script []byte) ([]string, error) {
122122
instrs := make([]string, 0)
123123

core/asm/compiler.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ type Compiler struct {
3939
debug bool
4040
}
4141

42-
// newCompiler returns a new allocated compiler.
42+
// NewCompiler returns a new allocated compiler.
4343
func NewCompiler(debug bool) *Compiler {
4444
return &Compiler{
4545
labels: make(map[string]int),
@@ -105,16 +105,16 @@ func (c *Compiler) Compile() (string, []error) {
105105
}
106106

107107
// turn the binary to hex
108-
var bin string
108+
var bin strings.Builder
109109
for _, v := range c.binary {
110110
switch v := v.(type) {
111111
case vm.OpCode:
112-
bin += fmt.Sprintf("%x", []byte{byte(v)})
112+
bin.WriteString(fmt.Sprintf("%x", []byte{byte(v)}))
113113
case []byte:
114-
bin += fmt.Sprintf("%x", v)
114+
bin.WriteString(fmt.Sprintf("%x", v))
115115
}
116116
}
117-
return bin, errors
117+
return bin.String(), errors
118118
}
119119

120120
// next returns the next token and increments the

core/asm/lexer.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ type lexer struct {
9393
debug bool // flag for triggering debug output
9494
}
9595

96-
// lex lexes the program by name with the given source. It returns a
96+
// Lex lexes the program by name with the given source. It returns a
9797
// channel on which the tokens are delivered.
9898
func Lex(source []byte, debug bool) <-chan token {
9999
ch := make(chan token)

0 commit comments

Comments
 (0)