Commit bf213313 authored by Kirill Smelkov's avatar Kirill Smelkov

X client: Cleanup a bit around decompressing

parent 57524491
...@@ -464,13 +464,10 @@ func (c *Client) _Load(ctx context.Context, xid zodb.Xid) (*mem.Buf, zodb.Tid, e ...@@ -464,13 +464,10 @@ func (c *Client) _Load(ctx context.Context, xid zodb.Xid) (*mem.Buf, zodb.Tid, e
} }
if resp.Compression { if resp.Compression {
// XXX cleanup mess vvv buf2 := &mem.Buf{Data: nil}
buf2 := mem.BufAlloc(len(buf.Data)) udata, err := xzlib.Decompress(buf.Data)
buf2.Data = buf2.Data[:0]
udata, err := xzlib.Decompress(buf.Data, buf2.Data)
buf.Release() buf.Release()
if err != nil { if err != nil {
buf2.Release()
return nil, 0, fmt.Errorf("data corrupt: %v", err) return nil, 0, fmt.Errorf("data corrupt: %v", err)
} }
buf2.Data = udata buf2.Data = udata
......
...@@ -65,12 +65,9 @@ func Compress(data []byte) (zdata []byte) { ...@@ -65,12 +65,9 @@ func Compress(data []byte) (zdata []byte) {
// Decompress decompresses data according to zlib encoding. // Decompress decompresses data according to zlib encoding.
// //
// out buffer, if there is enough capacity, is used for decompression destination.
// if out has not enough capacity a new buffer is allocated and used.
//
// return: destination buffer with full decompressed data or error. // return: destination buffer with full decompressed data or error.
func Decompress(in []byte, out []byte) (data []byte, err error) { func Decompress(zdata []byte) (data []byte, err error) {
return czlib.Decompress(in) return czlib.Decompress(zdata)
} }
/* /*
......
...@@ -38,7 +38,7 @@ var ztestv = []struct{in, out string}{ ...@@ -38,7 +38,7 @@ var ztestv = []struct{in, out string}{
func TestDecompress(t *testing.T) { func TestDecompress(t *testing.T) {
for _, tt := range ztestv { for _, tt := range ztestv {
got, err := Decompress([]byte(tt.in), nil) got, err := Decompress([]byte(tt.in))
if err != nil { if err != nil {
t.Errorf("decompress err: %q", tt.in) t.Errorf("decompress err: %q", tt.in)
continue continue
......
...@@ -471,6 +471,8 @@ func (stor *Storage) serveLink(ctx context.Context, req *neonet.Request, idReq * ...@@ -471,6 +471,8 @@ func (stor *Storage) serveLink(ctx context.Context, req *neonet.Request, idReq *
return err return err
} }
// XXX this go + link.Recv1() in serveClient arrange for N(goroutine) ↑
// with O(1/nreq) rate (i.e. N(goroutine, nreq) ~ ln(nreq)).
wg.Add(1) wg.Add(1)
go func() { go func() {
defer wg.Done() defer wg.Done()
......
...@@ -109,7 +109,7 @@ func BenchmarkUnzlib(b *testing.B, zfile string) { ...@@ -109,7 +109,7 @@ func BenchmarkUnzlib(b *testing.B, zfile string) {
b.ResetTimer() b.ResetTimer()
for i := 0; i < b.N; i++ { for i := 0; i < b.N; i++ {
_, err := xzlib.Decompress(zdata, nil) _, err := xzlib.Decompress(zdata)
if err != nil { if err != nil {
b.Fatal(err) b.Fatal(err)
} }
......
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