mirror of
https://github.com/golang/go
synced 2024-11-21 21:54:40 -07:00
image/jpeg: small memory layout optimization for encoding.
Before: jpeg.BenchmarkEncodeRGBOpaque ... 23.29 MB/s jpeg.BenchmarkEncodeRGBOpaque ... 23.27 MB/s jpeg.BenchmarkEncodeRGBOpaque ... 23.17 MB/s After: jpeg.BenchmarkEncodeRGBOpaque ... 23.42 MB/s jpeg.BenchmarkEncodeRGBOpaque ... 23.34 MB/s jpeg.BenchmarkEncodeRGBOpaque ... 23.33 MB/s R=rsc CC=golang-dev https://golang.org/cl/4538077
This commit is contained in:
parent
e7db6d78a2
commit
0a2650f398
@ -221,8 +221,7 @@ type encoder struct {
|
|||||||
// buf is a scratch buffer.
|
// buf is a scratch buffer.
|
||||||
buf [16]byte
|
buf [16]byte
|
||||||
// bits and nBits are accumulated bits to write to w.
|
// bits and nBits are accumulated bits to write to w.
|
||||||
bits uint32
|
bits, nBits uint32
|
||||||
nBits uint8
|
|
||||||
// quant is the scaled quantization tables.
|
// quant is the scaled quantization tables.
|
||||||
quant [nQuantIndex][blockSize]byte
|
quant [nQuantIndex][blockSize]byte
|
||||||
}
|
}
|
||||||
@ -250,7 +249,7 @@ func (e *encoder) writeByte(b byte) {
|
|||||||
|
|
||||||
// emit emits the least significant nBits bits of bits to the bitstream.
|
// emit emits the least significant nBits bits of bits to the bitstream.
|
||||||
// The precondition is bits < 1<<nBits && nBits <= 16.
|
// The precondition is bits < 1<<nBits && nBits <= 16.
|
||||||
func (e *encoder) emit(bits uint32, nBits uint8) {
|
func (e *encoder) emit(bits, nBits uint32) {
|
||||||
nBits += e.nBits
|
nBits += e.nBits
|
||||||
bits <<= 32 - nBits
|
bits <<= 32 - nBits
|
||||||
bits |= e.bits
|
bits |= e.bits
|
||||||
@ -269,7 +268,7 @@ func (e *encoder) emit(bits uint32, nBits uint8) {
|
|||||||
// emitHuff emits the given value with the given Huffman encoder.
|
// emitHuff emits the given value with the given Huffman encoder.
|
||||||
func (e *encoder) emitHuff(h huffIndex, value int) {
|
func (e *encoder) emitHuff(h huffIndex, value int) {
|
||||||
x := theHuffmanLUT[h][value]
|
x := theHuffmanLUT[h][value]
|
||||||
e.emit(x&(1<<24-1), uint8(x>>24))
|
e.emit(x&(1<<24-1), x>>24)
|
||||||
}
|
}
|
||||||
|
|
||||||
// emitHuffRLE emits a run of runLength copies of value encoded with the given
|
// emitHuffRLE emits a run of runLength copies of value encoded with the given
|
||||||
@ -279,11 +278,11 @@ func (e *encoder) emitHuffRLE(h huffIndex, runLength, value int) {
|
|||||||
if a < 0 {
|
if a < 0 {
|
||||||
a, b = -value, value-1
|
a, b = -value, value-1
|
||||||
}
|
}
|
||||||
var nBits uint8
|
var nBits uint32
|
||||||
if a < 0x100 {
|
if a < 0x100 {
|
||||||
nBits = bitCount[a]
|
nBits = uint32(bitCount[a])
|
||||||
} else {
|
} else {
|
||||||
nBits = 8 + bitCount[a>>8]
|
nBits = 8 + uint32(bitCount[a>>8])
|
||||||
}
|
}
|
||||||
e.emitHuff(h, runLength<<4|int(nBits))
|
e.emitHuff(h, runLength<<4|int(nBits))
|
||||||
if nBits > 0 {
|
if nBits > 0 {
|
||||||
|
Loading…
Reference in New Issue
Block a user