Skip to content

Commit 9d78a2f

Browse files
authored
optimize data reset (#4)
* optimize data reset * optimize data reset
1 parent b2b1adb commit 9d78a2f

File tree

5 files changed

+12
-49
lines changed

5 files changed

+12
-49
lines changed

.github/workflows/ci.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ jobs:
1212
runs-on: ubuntu-latest
1313
strategy:
1414
matrix:
15-
go: [ '1.22.11' ]
15+
go: [ '1.23.8' ]
1616
steps:
1717
- uses: actions/checkout@v3
1818

.github/workflows/codeql.yml

Lines changed: 0 additions & 38 deletions
This file was deleted.

.golangci.yml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11

22
run:
3-
go: "1.22.11"
3+
go: "1.23.8"
44
concurrency: 4
55
timeout: 5m
66
tests: false
@@ -205,7 +205,6 @@ linters:
205205
- nilerr
206206
- errorlint
207207
- bodyclose
208-
- exportloopref
209208
- gosec
210209
- lll
211210
fast: false

data/buffer.go

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,12 @@ func NewBuffer(size int) *Buffer {
3131
}
3232

3333
func (v *Buffer) Reset() {
34-
for i := 0; i < v.Size(); i++ {
35-
v.buf[i] = 0
34+
l := len(v.buf)
35+
if l > 5e6 {
36+
v.buf = v.buf[:0:5e6]
37+
} else {
38+
v.buf = v.buf[:0]
3639
}
37-
v.buf = v.buf[:0]
3840
v.pos = 0
3941
}
4042

@@ -151,12 +153,12 @@ func (v *Buffer) WriteAt(b []byte, off int64) (int, error) {
151153
off = 0
152154
}
153155

154-
if len(b)+int(off) > v.Size() {
155-
v.buf = append(v.buf[:off], b...)
156-
} else {
157-
copy(v.buf[off:], b[:])
156+
if add := len(b) + int(off) - v.Size(); add > 0 {
157+
v.buf = append(v.buf, make([]byte, add)...)
158158
}
159159

160+
copy(v.buf[off:], b[:])
161+
160162
return len(b), nil
161163
}
162164

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
module go.osspkg.com/ioutils
22

3-
go 1.22.11
3+
go 1.23.8
44

55
require (
66
go.osspkg.com/casecheck v0.3.0

0 commit comments

Comments
 (0)