Skip to content

Commit 79084ac

Browse files
Merge pull request #3 from sensiblecodeio/duncan/fix-cap
Fix block size computation
2 parents 99e4718 + 7718f28 commit 79084ac

File tree

3 files changed

+17
-14
lines changed

3 files changed

+17
-14
lines changed

.github/workflows/ci.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ jobs:
2424
- name: Set up Go
2525
uses: actions/setup-go@v2
2626
with:
27-
go-version: '~1.16.6'
27+
go-version: '~1.17.9'
2828
id: go
2929

3030
- name: Install utilities

uint32_store.go

+5-2
Original file line numberDiff line numberDiff line change
@@ -114,10 +114,13 @@ func (b *uint32Builder) alloc(nByteValues byte) []byteValue {
114114
*cur = (*cur)[: curLen+n : curCap]
115115
return (*cur)[curLen:]
116116
}
117-
newCap := curCap
118-
if newCap < maxBuildBufSize {
117+
newCap := curCap * 2
118+
for newCap < n {
119119
newCap *= 2
120120
}
121+
if newCap > maxBuildBufSize {
122+
newCap = maxBuildBufSize
123+
}
121124
a := make([]byteValue, n, newCap)
122125
b.all = append(b.all, a)
123126
return a

uint32_store_test.go

+11-11
Original file line numberDiff line numberDiff line change
@@ -14,22 +14,22 @@ import (
1414
)
1515

1616
func TestFastStringToUint32Empty(t *testing.T) {
17-
ms := mapSliceN(nil, 0)
18-
fm := faststringmap.NewUint32Store(ms)
19-
if keys := ms.AppendKeys(nil); len(keys) != 0 {
20-
t.Errorf("keys should be empty, got %#v", keys)
21-
}
22-
for _, k := range []string{"", "a", "foo", "ß"} {
23-
if actV, ok := fm.LookupString(k); ok {
24-
t.Errorf("%q present when not expected, got %d", k, actV)
25-
}
26-
}
17+
ms := mapSliceN(map[string]uint32{"": 1, "a": 2, "foo": 3, "ß": 4}, 0)
18+
checkWithMapSlice(t, ms)
19+
}
20+
21+
func TestFastStringToUint32BigSpan(t *testing.T) {
22+
ms := mapSliceN(map[string]uint32{"a!": 1, "a~": 2}, 2)
23+
checkWithMapSlice(t, ms)
2724
}
2825

2926
func TestFastStringToUint32(t *testing.T) {
3027
const nStrs = 8192
3128
m := randomSmallStrings(nStrs, 8)
32-
ms := mapSliceN(m, len(m)/2)
29+
checkWithMapSlice(t, mapSliceN(m, len(m)/2))
30+
}
31+
32+
func checkWithMapSlice(t *testing.T, ms mapSlice) {
3333
fm := faststringmap.NewUint32Store(ms)
3434

3535
for _, k := range ms.in {

0 commit comments

Comments
 (0)