Skip to content
This repository was archived by the owner on Oct 21, 2025. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
module github.com/ortuman/nuke

go 1.21.7
go 1.21.8

require github.com/stretchr/testify v1.8.4
require github.com/stretchr/testify v1.9.0

require (
github.com/davecgh/go-spew v1.1.1 // indirect
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk=
github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo=
github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg=
github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
Expand Down
22 changes: 7 additions & 15 deletions monotonic_arena.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ func (s *monotonicBuffer) alloc(size, alignment uintptr) (unsafe.Pointer, bool)
s.ptr = unsafe.Pointer(unsafe.SliceData(buf))
}
alignOffset := uintptr(0)
for alignedPtr := uintptr(s.ptr) + s.offset; alignedPtr%alignment != 0; alignedPtr++ {
alignOffset++
if delta := (uintptr(s.ptr) + s.offset) % alignment; delta > 0 {
alignOffset = alignment - delta
}
allocSize := size + alignOffset

Expand All @@ -37,15 +37,7 @@ func (s *monotonicBuffer) alloc(size, alignment uintptr) (unsafe.Pointer, bool)
ptr := unsafe.Pointer(uintptr(s.ptr) + s.offset + alignOffset)
s.offset += allocSize

// This piece of code will be translated into a runtime.memclrNoHeapPointers
// invocation by the compiler, which is an assembler optimized implementation.
// Architecture specific code can be found at src/runtime/memclr_$GOARCH.s
// in Go source (since https://codereview.appspot.com/137880043).
b := unsafe.Slice((*byte)(ptr), size)

for i := range b {
b[i] = 0
}
clear(unsafe.Slice((*byte)(ptr), size))

return ptr, true
}
Expand All @@ -67,7 +59,7 @@ func (s *monotonicBuffer) availableBytes() uintptr {

// NewMonotonicArena creates a new monotonic arena with a specified number of buffers and a buffer size.
func NewMonotonicArena(bufferSize, bufferCount int) Arena {
a := &monotonicArena{}
a := &monotonicArena{buffers: make([]*monotonicBuffer, 0, bufferCount)}
for i := 0; i < bufferCount; i++ {
a.buffers = append(a.buffers, newMonotonicBuffer(bufferSize))
}
Expand All @@ -76,7 +68,7 @@ func NewMonotonicArena(bufferSize, bufferCount int) Arena {

// Alloc satisfies the Arena interface.
func (a *monotonicArena) Alloc(size, alignment uintptr) unsafe.Pointer {
for i := 0; i < len(a.buffers); i++ {
for i := range a.buffers {
ptr, ok := a.buffers[i].alloc(size, alignment)
if ok {
return ptr
Expand All @@ -87,7 +79,7 @@ func (a *monotonicArena) Alloc(size, alignment uintptr) unsafe.Pointer {

// Reset satisfies the Arena interface.
func (a *monotonicArena) Reset(release bool) {
for _, s := range a.buffers {
s.reset(release)
for i := range a.buffers {
a.buffers[i].reset(release)
}
}