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)
} }
......
...@@ -50,14 +50,14 @@ func (d PyData) ClassName() string { ...@@ -50,14 +50,14 @@ func (d PyData) ClassName() string {
} }
if t, ok := xklass.(pickle.Tuple); ok { if t, ok := xklass.(pickle.Tuple); ok {
if len(t) != 2 { // (klass, args) if len(t) != 2 { // (klass, args)
return "?.?" return "?.?"
} }
xklass = t[0] xklass = t[0]
if t, ok := xklass.(pickle.Tuple); ok { if t, ok := xklass.(pickle.Tuple); ok {
// py: "old style reference" // py: "old style reference"
if len(t) != 2 { if len(t) != 2 {
return "?.?" // (modname, classname) return "?.?" // (modname, classname)
} }
return fmt.Sprintf("%s.%s", t...) return fmt.Sprintf("%s.%s", t...)
} }
......
...@@ -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)
} }
......
...@@ -49,7 +49,7 @@ func TestParseXTid(t *testing.T) { ...@@ -49,7 +49,7 @@ func TestParseXTid(t *testing.T) {
var testv = []struct {in string; xtid XTid; estr string} { var testv = []struct {in string; xtid XTid; estr string} {
{"", XTid{}, `xtid "" invalid`}, {"", XTid{}, `xtid "" invalid`},
{"a", XTid{}, `xtid "a" invalid`}, {"a", XTid{}, `xtid "a" invalid`},
{"0123456789abcdef", XTid{}, `xtid "0123456789abcdef" invalid`}, // XXX or let it be < by default ? {"0123456789abcdef", XTid{}, `xtid "0123456789abcdef" invalid`}, // XXX or let it be < by default ?
{"z0123456789abcdef", XTid{}, `xtid "z0123456789abcdef" invalid`}, {"z0123456789abcdef", XTid{}, `xtid "z0123456789abcdef" invalid`},
{"=0123456789abcdef", XTid{0x0123456789abcdef, false}, ""}, {"=0123456789abcdef", XTid{0x0123456789abcdef, false}, ""},
{"<0123456789abcdef", XTid{0x0123456789abcdef, true}, ""}, {"<0123456789abcdef", XTid{0x0123456789abcdef, true}, ""},
...@@ -59,7 +59,7 @@ func TestParseXTid(t *testing.T) { ...@@ -59,7 +59,7 @@ func TestParseXTid(t *testing.T) {
xtid, err := ParseXTid(tt.in) xtid, err := ParseXTid(tt.in)
if !(xtid == tt.xtid && estr(err) == tt.estr) { if !(xtid == tt.xtid && estr(err) == tt.estr) {
t.Errorf("parsextid: %v: test error:\nhave: %v %q\nwant: %v %q", t.Errorf("parsextid: %v: test error:\nhave: %v %q\nwant: %v %q",
tt.in, xtid, err, tt.xtid, tt.estr) tt.in, xtid, err, tt.xtid, tt.estr)
} }
} }
} }
...@@ -68,7 +68,7 @@ func TestParseXid(t *testing.T) { ...@@ -68,7 +68,7 @@ func TestParseXid(t *testing.T) {
var testv = []struct {in string; xid Xid; estr string} { var testv = []struct {in string; xid Xid; estr string} {
{"", Xid{}, `xid "" invalid`}, {"", Xid{}, `xid "" invalid`},
{"a", Xid{}, `xid "a" invalid`}, {"a", Xid{}, `xid "a" invalid`},
{"0123456789abcdef", Xid{}, `xid "0123456789abcdef" invalid`}, // XXX or let it be < by default ? {"0123456789abcdef", Xid{}, `xid "0123456789abcdef" invalid`}, // XXX or let it be < by default ?
{"z0123456789abcdef", Xid{}, `xid "z0123456789abcdef" invalid`}, {"z0123456789abcdef", Xid{}, `xid "z0123456789abcdef" invalid`},
{"=0123456789abcdef", Xid{}, `xid "=0123456789abcdef" invalid`}, {"=0123456789abcdef", Xid{}, `xid "=0123456789abcdef" invalid`},
{"<0123456789abcdef", Xid{}, `xid "<0123456789abcdef" invalid`}, {"<0123456789abcdef", Xid{}, `xid "<0123456789abcdef" invalid`},
...@@ -84,7 +84,7 @@ func TestParseXid(t *testing.T) { ...@@ -84,7 +84,7 @@ func TestParseXid(t *testing.T) {
xid, err := ParseXid(tt.in) xid, err := ParseXid(tt.in)
if !(xid == tt.xid && estr(err) == tt.estr) { if !(xid == tt.xid && estr(err) == tt.estr) {
t.Errorf("parsexid: %v: test error:\nhave: %v %q\nwant: %v %q", t.Errorf("parsexid: %v: test error:\nhave: %v %q\nwant: %v %q",
tt.in, xid, err, tt.xid, tt.estr) tt.in, xid, err, tt.xid, tt.estr)
} }
} }
} }
......
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