This repository was archived by the owner on Jul 31, 2023. It is now read-only.
File tree Expand file tree Collapse file tree 5 files changed +14
-14
lines changed Expand file tree Collapse file tree 5 files changed +14
-14
lines changed Original file line number Diff line number Diff line change @@ -171,7 +171,7 @@ func Test_View_MeasureFloat64_AggregationDistribution(t *testing.T) {
171
171
}
172
172
ctx , err := tag .New (context .Background (), mods ... )
173
173
if err != nil {
174
- t .Errorf ("%v: NewMap = %v" , tc .label , err )
174
+ t .Errorf ("%v: New = %v" , tc .label , err )
175
175
}
176
176
view .addSample (tag .FromContext (ctx ), r .f )
177
177
}
Original file line number Diff line number Diff line change @@ -28,13 +28,13 @@ type Tag struct {
28
28
Value string
29
29
}
30
30
31
- // Map is a map of tags. Use NewMap to build tag maps.
31
+ // Map is a map of tags. Use New to create a context containing
32
+ // a new Map.
32
33
type Map struct {
33
34
m map [Key ]string
34
35
}
35
36
36
- // Value returns the value for the key if a value
37
- // for the key exists.
37
+ // Value returns the value for the key if a value for the key exists.
38
38
func (m * Map ) Value (k Key ) (string , bool ) {
39
39
if m == nil {
40
40
return "" , false
@@ -47,7 +47,7 @@ func (m *Map) String() string {
47
47
if m == nil {
48
48
return "nil"
49
49
}
50
- var keys []Key
50
+ keys := make ( []Key , 0 , len ( m . m ))
51
51
for k := range m .m {
52
52
keys = append (keys , k )
53
53
}
@@ -83,8 +83,8 @@ func (m *Map) delete(k Key) {
83
83
delete (m .m , k )
84
84
}
85
85
86
- func newMap (sizeHint int ) * Map {
87
- return & Map {m : make (map [Key ]string , sizeHint )}
86
+ func newMap () * Map {
87
+ return & Map {m : make (map [Key ]string )}
88
88
}
89
89
90
90
// Mutator modifies a tag map.
@@ -153,7 +153,7 @@ func Delete(k Key) Mutator {
153
153
// originated from the incoming context and modified
154
154
// with the provided mutators.
155
155
func New (ctx context.Context , mutator ... Mutator ) (context.Context , error ) {
156
- m := newMap (0 )
156
+ m := newMap ()
157
157
orig := FromContext (ctx )
158
158
if orig != nil {
159
159
for k , v := range orig .m {
Original file line number Diff line number Diff line change @@ -176,7 +176,7 @@ func Encode(m *Map) []byte {
176
176
177
177
// Decode decodes the given []byte into a tag map.
178
178
func Decode (bytes []byte ) (* Map , error ) {
179
- ts := newMap (0 )
179
+ ts := newMap ()
180
180
181
181
eg := & encoderGRPC {
182
182
buf : bytes ,
Original file line number Diff line number Diff line change @@ -80,7 +80,7 @@ func TestEncodeDecode(t *testing.T) {
80
80
}
81
81
ctx , err := New (context .Background (), mods ... )
82
82
if err != nil {
83
- t .Errorf ("%v: NewMap = %v" , tc .label , err )
83
+ t .Errorf ("%v: New = %v" , tc .label , err )
84
84
}
85
85
86
86
encoded := Encode (FromContext (ctx ))
Original file line number Diff line number Diff line change @@ -33,7 +33,7 @@ func TestContext(t *testing.T) {
33
33
Insert (k2 , "v2" ),
34
34
)
35
35
got := FromContext (ctx )
36
- want := newMap (2 )
36
+ want := newMap ()
37
37
want .insert (k1 , "v1" )
38
38
want .insert (k2 , "v2" )
39
39
@@ -51,7 +51,7 @@ func TestDo(t *testing.T) {
51
51
Insert (k2 , "v2" ),
52
52
)
53
53
got := FromContext (ctx )
54
- want := newMap (2 )
54
+ want := newMap ()
55
55
want .insert (k1 , "v1" )
56
56
want .insert (k2 , "v2" )
57
57
Do (ctx , func (ctx context.Context ) {
@@ -168,7 +168,7 @@ func TestNewMap(t *testing.T) {
168
168
}
169
169
}
170
170
171
- func TestNewMapValidation (t * testing.T ) {
171
+ func TestNewValidation (t * testing.T ) {
172
172
tests := []struct {
173
173
err string
174
174
seed * Map
@@ -213,7 +213,7 @@ func TestNewMapValidation(t *testing.T) {
213
213
}
214
214
215
215
func makeTestTagMap (ids ... int ) * Map {
216
- m := newMap (len ( ids ) )
216
+ m := newMap ()
217
217
for _ , v := range ids {
218
218
k , _ := NewKey (fmt .Sprintf ("k%d" , v ))
219
219
m .m [k ] = fmt .Sprintf ("v%d" , v )
You can’t perform that action at this time.
0 commit comments