This repository was archived by the owner on Jun 5, 2021. It is now read-only.
File tree Expand file tree Collapse file tree 2 files changed +6
-12
lines changed Expand file tree Collapse file tree 2 files changed +6
-12
lines changed Original file line number Diff line number Diff line change @@ -104,17 +104,11 @@ func (m *Message) Reset() {
104
104
m .Attributes = m .Attributes [:0 ]
105
105
}
106
106
107
- // grow ensures that internal buffer will fit v more bytes and
108
- // increases it capacity if necessary.
109
- func (m * Message ) grow (v int ) {
110
- // Not performing any optimizations here
111
- // (e.g. preallocate len(buf) * 2 to reduce allocations)
112
- // because they are already done by []byte implementation.
113
- n := len (m .Raw ) + v
114
- for cap (m .Raw ) < n {
107
+ // grow ensures that internal buffer has n length.
108
+ func (m * Message ) grow (n int ) {
109
+ for len (m .Raw ) < n {
115
110
m .Raw = append (m .Raw , 0 )
116
111
}
117
- m .Raw = m .Raw [:n ]
118
112
}
119
113
120
114
// Add appends new attribute to message. Not goroutine-safe.
Original file line number Diff line number Diff line change @@ -472,18 +472,18 @@ func TestMessage_Equal(t *testing.T) {
472
472
func TestMessageGrow (t * testing.T ) {
473
473
m := New ()
474
474
m .grow (512 )
475
- if len (m .Raw ) < 532 {
475
+ if len (m .Raw ) < 512 {
476
476
t .Error ("Bad length" , len (m .Raw ))
477
477
}
478
478
}
479
479
480
480
func TestMessageGrowSmaller (t * testing.T ) {
481
481
m := New ()
482
482
m .grow (2 )
483
- if cap (m .Raw ) < 22 {
483
+ if cap (m .Raw ) < 20 {
484
484
t .Error ("Bad capacity" , cap (m .Raw ))
485
485
}
486
- if len (m .Raw ) < 22 {
486
+ if len (m .Raw ) < 20 {
487
487
t .Error ("Bad length" , len (m .Raw ))
488
488
}
489
489
}
You can’t perform that action at this time.
0 commit comments