Skip to content

Commit

Permalink
performance opt: using copy instead of append
Browse files Browse the repository at this point in the history
  • Loading branch information
wathenjiang committed Mar 5, 2022
1 parent d374463 commit 5fd6552
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions memlog.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@ func (r Record) deepCopy() Record {
if r.Metadata.Offset == 0 && r.Metadata.Created.IsZero() {
return Record{}
}

dCopy := append([]byte(nil), r.Data...)
dCopy := make([]byte, len(r.Data))
copy(dCopy, r.Data)
return Record{
Metadata: Header{
Offset: r.Metadata.Offset,
Expand Down Expand Up @@ -139,13 +139,14 @@ func (l *Log) write(ctx context.Context, data []byte) (Offset, error) {
return -1, errors.New("no data provided")
}

dcopy := append([]byte(nil), data...)
dCopy := make([]byte, len(data))
copy(dCopy, data)
r := Record{
Metadata: Header{
Offset: l.offset,
Created: l.clock.Now().UTC(),
},
Data: dcopy,
Data: dCopy,
}

err := l.active.write(ctx, r)
Expand Down

0 comments on commit 5fd6552

Please sign in to comment.