File tree Expand file tree Collapse file tree 2 files changed +7
-4
lines changed
Expand file tree Collapse file tree 2 files changed +7
-4
lines changed Original file line number Diff line number Diff line change @@ -746,7 +746,8 @@ func (f *framer) setLength(length int) {
746746}
747747
748748func (f * framer ) finish () error {
749- if len (f .buf ) > maxFrameSize {
749+ bufLen := len (f .buf )
750+ if bufLen > maxFrameSize {
750751 // huge app frame, lets remove it so it doesn't bloat the heap
751752 f .buf = make ([]byte , defaultBufSize )
752753 return ErrFrameTooBig
@@ -764,8 +765,9 @@ func (f *framer) finish() error {
764765 }
765766
766767 f .buf = append (f .buf [:headSize ], compressed ... )
768+ bufLen = len (f .buf )
767769 }
768- length := len ( f . buf ) - headSize
770+ length := bufLen - headSize
769771 f .setLength (length )
770772
771773 return nil
Original file line number Diff line number Diff line change @@ -48,7 +48,8 @@ func (s LZ4Compressor) Name() string {
4848}
4949
5050func (s LZ4Compressor ) Encode (data []byte ) ([]byte , error ) {
51- buf := make ([]byte , lz4 .CompressBlockBound (len (data )+ 4 ))
51+ dataLen := len (data )
52+ buf := make ([]byte , lz4 .CompressBlockBound (dataLen )+ 4 )
5253 var compressor lz4.Compressor
5354 n , err := compressor .CompressBlock (data , buf [4 :])
5455 // According to lz4.CompressBlock doc, it doesn't fail as long as the dst
@@ -57,7 +58,7 @@ func (s LZ4Compressor) Encode(data []byte) ([]byte, error) {
5758 if err != nil {
5859 return nil , err
5960 }
60- binary .BigEndian .PutUint32 (buf , uint32 (len ( data ) ))
61+ binary .BigEndian .PutUint32 (buf , uint32 (dataLen ))
6162 return buf [:n + 4 ], nil
6263}
6364
You can’t perform that action at this time.
0 commit comments