Skip to content

Commit 24ae769

Browse files
committed
optimise by using struct, not pointer to it
1 parent 7b9922d commit 24ae769

File tree

2 files changed

+5
-7
lines changed

2 files changed

+5
-7
lines changed

binary.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ func Marshal(iface interface{}) (bytes []byte, e error) {
2020
)
2121

2222
var (
23-
operation *codecOperation
23+
operation codecOperation
2424
)
2525

2626
defer func() {
@@ -56,7 +56,7 @@ func Unmarshal(bytes []byte, iface interface{}) (e error) {
5656
)
5757

5858
var (
59-
operation *codecOperation
59+
operation codecOperation
6060
)
6161

6262
defer func() {

codec.go

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -56,10 +56,8 @@ func (c *codec) formatMetadataFromTypeReflection(reflection reflect.Type) (
5656
}
5757

5858
func (c *codec) newOperation(iface interface{}) (
59-
operation *codecOperation, e error,
59+
operation codecOperation, e error,
6060
) {
61-
operation = new(codecOperation)
62-
6361
operation.format, e = c.formatMetadataFromTypeReflection(
6462
reflect.TypeOf(iface),
6563
)
@@ -77,13 +75,13 @@ type codecOperation struct {
7775
valueReflection reflect.Value
7876
}
7977

80-
func (c *codecOperation) marshal() (bytes []byte, e error) {
78+
func (c codecOperation) marshal() (bytes []byte, e error) {
8179
bytes = c.format.marshal(c.valueReflection)
8280

8381
return
8482
}
8583

86-
func (c *codecOperation) unmarshal(bytes []byte) (e error) {
84+
func (c codecOperation) unmarshal(bytes []byte) (e error) {
8785
if len(bytes) != c.format.lengthInBytes {
8886
e = validation.NewLengthOfByteSliceNotEqualToFormatLengthError(
8987
uint(c.format.lengthInBytes),

0 commit comments

Comments
 (0)