File tree 2 files changed +22
-3
lines changed
2 files changed +22
-3
lines changed Original file line number Diff line number Diff line change 84
84
digitsLZ4 = mustLoadFile ("testdata/e.txt.lz4" )
85
85
twainLZ4 = mustLoadFile ("testdata/Mark.Twain-Tom.Sawyer.txt.lz4" )
86
86
randomLZ4 = mustLoadFile ("testdata/random.data.lz4" )
87
+ repeatLz4 = mustLoadFile ("testdata/repeat.txt.lz4" )
87
88
)
88
89
89
90
func benchmarkUncompress (b * testing.B , compressed []byte ) {
@@ -160,3 +161,19 @@ func BenchmarkWriterReset(b *testing.B) {
160
161
_ = zw .Close ()
161
162
}
162
163
}
164
+
165
+ func BenchmarkReaderNoReset (b * testing.B ) {
166
+ compressed := repeatLz4
167
+ b .ReportAllocs ()
168
+ b .ResetTimer ()
169
+
170
+ for i := 0 ; i < b .N ; i ++ {
171
+ r := bytes .NewReader (compressed )
172
+ zr := lz4 .NewReader (r )
173
+ buf := bytes .NewBuffer (nil )
174
+ _ , err := buf .ReadFrom (zr )
175
+ if err != nil {
176
+ b .Fatal (err )
177
+ }
178
+ }
179
+ }
Original file line number Diff line number Diff line change @@ -135,6 +135,8 @@ func (r *Reader) Read(buf []byte) (n int, err error) {
135
135
}
136
136
lz4block .Put (r .data )
137
137
r .data = nil
138
+ // reset frame to release the buffer held by Block
139
+ r .frame .Reset (r .num )
138
140
return
139
141
default :
140
142
return
@@ -157,9 +159,9 @@ func (r *Reader) Read(buf []byte) (n int, err error) {
157
159
}
158
160
159
161
// read uncompresses the next block as follow:
160
- // - if buf has enough room, the block is uncompressed into it directly
161
- // and the lenght of used space is returned
162
- // - else, the uncompress data is stored in r.data and 0 is returned
162
+ // - if buf has enough room, the block is uncompressed into it directly
163
+ // and the lenght of used space is returned
164
+ // - else, the uncompress data is stored in r.data and 0 is returned
163
165
func (r * Reader ) read (buf []byte ) (int , error ) {
164
166
block := r .frame .Blocks .Block
165
167
_ , err := block .Read (r .frame , r .src , r .cum )
You can’t perform that action at this time.
0 commit comments