summaryrefslogtreecommitdiff
path: root/vendor/go.etcd.io/bbolt/tx.go
diff options
context:
space:
mode:
Diffstat (limited to 'vendor/go.etcd.io/bbolt/tx.go')
-rw-r--r--vendor/go.etcd.io/bbolt/tx.go27
1 files changed, 8 insertions, 19 deletions
diff --git a/vendor/go.etcd.io/bbolt/tx.go b/vendor/go.etcd.io/bbolt/tx.go
index 13937cdbf..4b1a64a8b 100644
--- a/vendor/go.etcd.io/bbolt/tx.go
+++ b/vendor/go.etcd.io/bbolt/tx.go
@@ -4,7 +4,6 @@ import (
"fmt"
"io"
"os"
- "reflect"
"sort"
"strings"
"time"
@@ -524,24 +523,18 @@ func (tx *Tx) write() error {
// Write pages to disk in order.
for _, p := range pages {
- size := (int(p.overflow) + 1) * tx.db.pageSize
+ rem := (uint64(p.overflow) + 1) * uint64(tx.db.pageSize)
offset := int64(p.id) * int64(tx.db.pageSize)
+ var written uintptr
// Write out page in "max allocation" sized chunks.
- ptr := uintptr(unsafe.Pointer(p))
for {
- // Limit our write to our max allocation size.
- sz := size
+ sz := rem
if sz > maxAllocSize-1 {
sz = maxAllocSize - 1
}
+ buf := unsafeByteSlice(unsafe.Pointer(p), written, 0, int(sz))
- // Write chunk to disk.
- buf := *(*[]byte)(unsafe.Pointer(&reflect.SliceHeader{
- Data: ptr,
- Len: sz,
- Cap: sz,
- }))
if _, err := tx.db.ops.writeAt(buf, offset); err != nil {
return err
}
@@ -550,14 +543,14 @@ func (tx *Tx) write() error {
tx.stats.Write++
// Exit inner for loop if we've written all the chunks.
- size -= sz
- if size == 0 {
+ rem -= sz
+ if rem == 0 {
break
}
// Otherwise move offset forward and move pointer to next chunk.
offset += int64(sz)
- ptr += uintptr(sz)
+ written += uintptr(sz)
}
}
@@ -576,11 +569,7 @@ func (tx *Tx) write() error {
continue
}
- buf := *(*[]byte)(unsafe.Pointer(&reflect.SliceHeader{
- Data: uintptr(unsafe.Pointer(p)),
- Len: tx.db.pageSize,
- Cap: tx.db.pageSize,
- }))
+ buf := unsafeByteSlice(unsafe.Pointer(p), 0, 0, tx.db.pageSize)
// See https://go.googlesource.com/go/+/f03c9202c43e0abb130669852082117ca50aa9b1
for i := range buf {