Skip to content

Commit

Permalink
bufio: reduce pointer size in structs for better memory alignment and…
Browse files Browse the repository at this point in the history
… efficiency
  • Loading branch information
bernoussama committed Nov 16, 2024
1 parent ff2376d commit 95c71fa
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
8 changes: 5 additions & 3 deletions src/bufio/bufio.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,10 @@ type Reader struct {
lastRuneSize int // size of last rune read for UnreadRune; -1 means invalid
}

const minReadBufferSize = 16
const maxConsecutiveEmptyReads = 100
const (
minReadBufferSize = 16
maxConsecutiveEmptyReads = 100
)

// NewReaderSize returns a new [Reader] whose buffer has at least the specified
// size. If the argument io.Reader is already a [Reader] with large enough
Expand Down Expand Up @@ -575,9 +577,9 @@ func (b *Reader) writeBuf(w io.Writer) (int64, error) {
// the underlying [io.Writer].
type Writer struct {
err error
wr io.Writer
buf []byte
n int
wr io.Writer
}

// NewWriterSize returns a new [Writer] whose buffer has at least the specified
Expand Down
4 changes: 2 additions & 2 deletions src/bufio/scan.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,13 @@ import (
// on a reader, should use [bufio.Reader] instead.
type Scanner struct {
r io.Reader // The reader provided by the client.
err error // Sticky error.
split SplitFunc // The function to split the tokens.
maxTokenSize int // Maximum size of a token; modified by tests.
token []byte // Last token returned by split.
buf []byte // Buffer used as argument to split.
maxTokenSize int // Maximum size of a token; modified by tests.
start int // First non-processed byte in buf.
end int // End of data in buf.
err error // Sticky error.
empties int // Count of successive empty tokens.
scanCalled bool // Scan has been called; buffer is in use.
done bool // Scan has finished.
Expand Down

0 comments on commit 95c71fa

Please sign in to comment.