Commit 2c03f1f6 authored by Kirill Smelkov's avatar Kirill Smelkov

.

parent e796a2b6
...@@ -34,7 +34,7 @@ import ( ...@@ -34,7 +34,7 @@ import (
// //
// Custom allocation functions affect only performance, not correctness - // Custom allocation functions affect only performance, not correctness -
// everything should work if data buffer is allocated and/or free'ed // everything should work if data buffer is allocated and/or free'ed
// regular Go/GC-way. // via regular Go/GC-way.
type Buf struct { type Buf struct {
Data []byte Data []byte
...@@ -54,10 +54,9 @@ func init() { ...@@ -54,10 +54,9 @@ func init() {
for i := 0; i < len(bufPoolv); i++ { for i := 0; i < len(bufPoolv); i++ {
i := i i := i
bufPoolv[i].New = func() interface{} { bufPoolv[i].New = func() interface{} {
//println("X allocating for order", i)
// NOTE *Buf, not just buf, to avoid allocation when // NOTE *Buf, not just buf, to avoid allocation when
// making interface{} from it (interface{} wants to always point to heap) // making interface{} from it (interface{} wants to always point to heap)
return &Buf{Data: make([]byte, 1 << (order0 + uint(i)))} return &Buf{Data: make([]byte, 1<<(order0+uint(i)))}
} }
} }
} }
...@@ -116,9 +115,7 @@ func (buf *Buf) Release() { ...@@ -116,9 +115,7 @@ func (buf *Buf) Release() {
} }
// order = max i: 2^i <= cap // order = max i: 2^i <= cap
//order := bits.Len(uint(cap(buf.Data)))
order := xmath.FloorLog2(uint64(cap(buf.Data))) order := xmath.FloorLog2(uint64(cap(buf.Data)))
//println("YYY free", cap(buf.Data), "-> order:", order)
order -= order0 order -= order0
if order < 0 { if order < 0 {
......
...@@ -51,9 +51,9 @@ func TestBufAllocFree(t *testing.T) { ...@@ -51,9 +51,9 @@ func TestBufAllocFree(t *testing.T) {
xcap := 1<<i xcap := 1<<i
buf := BufAlloc(size) buf := BufAlloc(size)
if i < order0 { if i < order0 {
xcap = 1<<order0 xcap = 1 << order0
} }
if int(i) >= order0 + len(bufPoolv) { if int(i) >= order0+len(bufPoolv) {
xcap = size xcap = size
} }
...@@ -80,7 +80,7 @@ func TestBufAllocFree(t *testing.T) { ...@@ -80,7 +80,7 @@ func TestBufAllocFree(t *testing.T) {
buf2 := BufAlloc(size) buf2 := BufAlloc(size)
// not from pool - memory won't be reused // not from pool - memory won't be reused
if int(i) >= order0 + len(bufPoolv) { if int(i) >= order0+len(bufPoolv) {
if buf2 == buf || sliceDataPtr(buf2.Data) == sliceDataPtr(data) { if buf2 == buf || sliceDataPtr(buf2.Data) == sliceDataPtr(data) {
t.Fatalf("%v: buffer reused but should not", i) t.Fatalf("%v: buffer reused but should not", i)
} }
......
...@@ -63,10 +63,10 @@ func (xtid XTid) String() string { ...@@ -63,10 +63,10 @@ func (xtid XTid) String() string {
} }
func (xid Xid) String() string { func (xid Xid) String() string {
return xid.XTid.String() + ":" + xid.Oid.String() // XXX use "·" instead of ":" ? return xid.XTid.String() + ":" + xid.Oid.String()
} }
/* TODO reenable /* TODO reenable?
func (xtid XTid) XFmtString(b []byte) []byte { func (xtid XTid) XFmtString(b []byte) []byte {
b .C("=<"[bint(xtid.TidBefore)]) .V(xtid.Tid) b .C("=<"[bint(xtid.TidBefore)]) .V(xtid.Tid)
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment