Skip to content

Commit

Permalink
Merge pull request #38 from spongecaptain/main
Browse files Browse the repository at this point in the history
performance opt: using copy instead of append
  • Loading branch information
Michael Gasch committed Mar 6, 2022
2 parents d374463 + 5fd6552 commit dfaa93d
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions memlog.go
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 dfaa93d

Please sign in to comment.