Skip to content

Commit

Permalink
Don't copy strings when reading them in
Browse files Browse the repository at this point in the history
  • Loading branch information
actgardner committed Oct 11, 2021
1 parent f71f636 commit 568c540
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 2 deletions.
3 changes: 2 additions & 1 deletion v9/vm/reader_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,9 @@ import (
)

func BenchmarkReadBool(b *testing.B) {
buf := make([]byte, 8)
for i := 0; i < b.N; i++ {
r := bytes.NewBuffer([]byte{1})
readBool(r)
readBool(r, buf)
}
}
3 changes: 2 additions & 1 deletion v9/vm/readers.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"fmt"
"io"
"math"
"unsafe"
)

type ByteReader interface {
Expand Down Expand Up @@ -153,7 +154,7 @@ func readString(r io.Reader, buf []byte) (string, error) {
if err != nil {
return "", err
}
return string(bb), nil
return *(*string)(unsafe.Pointer(&bb)), nil
}

func readFixed(r io.Reader, size int) ([]byte, error) {
Expand Down

0 comments on commit 568c540

Please sign in to comment.