Skip to content

Commit 9881204

Browse files
committed
Do not export Attrs.Encode() method.
1 parent f411309 commit 9881204

4 files changed

Lines changed: 30 additions & 8 deletions

File tree

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
## v0.1.0
2+
3+
- Pass `context.Context` to `Comment` method.
4+
- Do not export `Attrs.Encode()` method.
5+
16
## v0.0.1
27

38
- Initial release.

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55

66
Go implementation of https://google.github.io/sqlcommenter/.
77

8+
Public API is not stable, expect breaking changes.
9+
810
## Usage with pgx stdlib driver
911

1012
```go

attrs.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,13 @@ type Attr struct {
2424

2525
type Attrs map[string]string
2626

27-
func (a Attrs) Encode() string {
27+
func (a Attrs) Update(other Attrs) {
28+
for k, v := range other {
29+
a[k] = v
30+
}
31+
}
32+
33+
func (a Attrs) encode() string {
2834
total := len(a)
2935
keys := make([]string, 0, total)
3036
for k := range a {
@@ -44,12 +50,6 @@ func (a Attrs) Encode() string {
4450
return b.String()
4551
}
4652

47-
func (a Attrs) Update(other Attrs) {
48-
for k, v := range other {
49-
a[k] = v
50-
}
51-
}
52-
5353
func encodeKey(k string) string {
5454
return url.QueryEscape(k)
5555
}

attrs_test.go

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,25 @@ func TestAttrsEncode(t *testing.T) {
3333

3434
for _, cs := range cases {
3535
t.Run(cs.name, func(t *testing.T) {
36-
got := cs.attrs.Encode()
36+
got := cs.attrs.encode()
3737
if want := cs.want; want != got {
3838
t.Errorf("got '%v', want '%v'", got, want)
3939
}
4040
})
4141
}
4242
}
43+
44+
func BenchmarkAttrsEncode(b *testing.B) {
45+
b.ReportAllocs()
46+
b.SetBytes(2)
47+
48+
attrs := Attrs(map[string]string{
49+
"key": "value",
50+
"2key": "value 33",
51+
"key3": "44 value",
52+
})
53+
54+
for i := 0; i < b.N; i++ {
55+
attrs.encode()
56+
}
57+
}

0 commit comments

Comments
 (0)