mirror of
https://github.com/golang/go
synced 2024-11-24 23:57:57 -07:00
bufio: reduce pointer size in structs for better memory alignment and efficiency
This commit is contained in:
parent
ff2376dbe3
commit
95c71fa44e
@ -38,8 +38,10 @@ type Reader struct {
|
|||||||
lastRuneSize int // size of last rune read for UnreadRune; -1 means invalid
|
lastRuneSize int // size of last rune read for UnreadRune; -1 means invalid
|
||||||
}
|
}
|
||||||
|
|
||||||
const minReadBufferSize = 16
|
const (
|
||||||
const maxConsecutiveEmptyReads = 100
|
minReadBufferSize = 16
|
||||||
|
maxConsecutiveEmptyReads = 100
|
||||||
|
)
|
||||||
|
|
||||||
// NewReaderSize returns a new [Reader] whose buffer has at least the specified
|
// 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
|
// size. If the argument io.Reader is already a [Reader] with large enough
|
||||||
@ -575,9 +577,9 @@ func (b *Reader) writeBuf(w io.Writer) (int64, error) {
|
|||||||
// the underlying [io.Writer].
|
// the underlying [io.Writer].
|
||||||
type Writer struct {
|
type Writer struct {
|
||||||
err error
|
err error
|
||||||
|
wr io.Writer
|
||||||
buf []byte
|
buf []byte
|
||||||
n int
|
n int
|
||||||
wr io.Writer
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewWriterSize returns a new [Writer] whose buffer has at least the specified
|
// NewWriterSize returns a new [Writer] whose buffer has at least the specified
|
||||||
|
@ -28,13 +28,13 @@ import (
|
|||||||
// on a reader, should use [bufio.Reader] instead.
|
// on a reader, should use [bufio.Reader] instead.
|
||||||
type Scanner struct {
|
type Scanner struct {
|
||||||
r io.Reader // The reader provided by the client.
|
r io.Reader // The reader provided by the client.
|
||||||
|
err error // Sticky error.
|
||||||
split SplitFunc // The function to split the tokens.
|
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.
|
token []byte // Last token returned by split.
|
||||||
buf []byte // Buffer used as argument to 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.
|
start int // First non-processed byte in buf.
|
||||||
end int // End of data in buf.
|
end int // End of data in buf.
|
||||||
err error // Sticky error.
|
|
||||||
empties int // Count of successive empty tokens.
|
empties int // Count of successive empty tokens.
|
||||||
scanCalled bool // Scan has been called; buffer is in use.
|
scanCalled bool // Scan has been called; buffer is in use.
|
||||||
done bool // Scan has finished.
|
done bool // Scan has finished.
|
||||||
|
Loading…
Reference in New Issue
Block a user