8000 use a shared buf · golang/text@7e21e25 · GitHub
[go: up one dir, main page]

Skip to content

Commit 7e21e25

Browse files
committed
use a shared buf
1 parent f1daf0a commit 7e21e25

File tree

1 file changed

+7
-7
lines changed

1 file changed

+7
-7
lines changed

collate/collate.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,14 @@ import (
1919
)
2020

2121
// Collator provides functionality for comparing strings for a given
22-
// collation order.
22+
// collation order. A given Collator is not safe to use concurrently.
2323
type Collator struct {
2424
options
2525

2626
sorter sorter
2727

28+
buf Buffer
29+
2830
_iter [2]iter
2931
}
3032

@@ -106,9 +108,8 @@ func (b *Buffer) Reset() {
106108
// a new buffer will be allocated for each call.
107109
func (c *Collator) Compare(a, b []byte) int {
108110
var (
109-
buf Buffer
110-
kA = c.Key(&buf, a)
111-
kB = c.Key(&buf, b)
111+
kA = c.Key(&c.buf, a)
112+
kB = c.Key(&c.buf, b)
112113
)
113114
return bytes.Compare(kA, kB)
114115
}
@@ -119,9 +120,8 @@ func (c *Collator) Compare(a, b []byte) int {
119120
// a new buffer will be allocated for each call.
120121
func (c *Collator) CompareString(a, b string) int {
121122
var (
122-
buf Buffer
123-
kA = c.KeyFromString(&buf, a)
124-
kB = c.KeyFromString(&buf, b)
123+
kA = c.KeyFromString(&c.buf, a)
124+
kB = c.KeyFromString(&c.buf, b)
125125
)
126126
return bytes.Compare(kA, kB)
127127
}

0 commit comments

Comments
 (0)
0