Commit f1278d15 authored by Kirill Smelkov's avatar Kirill Smelkov

.

parent 0332d46d
......@@ -32,8 +32,8 @@ import (
"../../../../storage/fs1"
"../../../../xcommon/xbufio"
"../../../../xcommon/xbytes"
"../../../../xcommon/xfmt"
"../../../../xcommon/xslice"
)
......@@ -105,7 +105,7 @@ func fsTail(w io.Writer, path string, ntxn int) (err error) {
// read raw data inside transaction record
dataLen := txnh.DataLen()
data = xslice.Realloc64(data, dataLen)
data = xbytes.Realloc64(data, dataLen)
_, err = fSeq.ReadAt(data, txnh.DataPos())
if err != nil {
// XXX -> txnh.Err(...) ?
......
......@@ -24,7 +24,7 @@ import (
"../../zodb"
"../../xcommon/xbufio"
"../../xcommon/xslice"
"../../xcommon/xbytes"
)
// FileStorage is a ZODB storage which stores data in simple append-only file
......@@ -194,7 +194,7 @@ func (txnh *TxnHeader) DataLen() int64 {
func (txnh *TxnHeader) CloneFrom(txnh2 *TxnHeader) {
workMem := txnh.workMem
lwork2 := len(txnh2.workMem)
workMem = xslice.Realloc(workMem, lwork2)
workMem = xbytes.Realloc(workMem, lwork2)
*txnh = *txnh2
// now unshare slices
txnh.workMem = workMem
......@@ -311,7 +311,7 @@ func (txnh *TxnHeader) Load(r io.ReaderAt /* *os.File */, pos int64, flags TxnLo
}
// NOTE we encode whole strings length into len(.workMem)
txnh.workMem = xslice.Realloc(txnh.workMem, lstr)
txnh.workMem = xbytes.Realloc(txnh.workMem, lstr)
// NOTE we encode each x string length into cap(x)
// and set len(x) = 0 to indicate x is not loaded yet
......@@ -646,7 +646,7 @@ func (dh *DataHeader) LoadData(r io.ReaderAt /* *os.File */, buf *[]byte) error
}
// now read actual data
*buf = xslice.Realloc64(*buf, dh.DataLen)
*buf = xbytes.Realloc64(*buf, dh.DataLen)
_, err := r.ReadAt(*buf, dh.Pos + DataHeaderSize)
if err != nil {
return dh.err("read data", noEOF(err)) // XXX recheck
......
......@@ -15,9 +15,9 @@
//
// See COPYING file for full licensing terms.
// Package xbytes provides addons to std package bytes
// Package xbytes provides additional utilities for working with (XXX byte) slices
package xslice
// (re)allocation routines for []byte
package xbytes
import (
"../xmath"
......
......@@ -15,7 +15,7 @@
//
// See COPYING file for full licensing terms.
package xslice
package xbytes
import (
"bytes"
......
// Copyright (C) 2017 Nexedi SA and Contributors.
// Kirill Smelkov <kirr@nexedi.com>
//
// This program is free software: you can Use, Study, Modify and Redistribute
// it under the terms of the GNU General Public License version 3, or (at your
// option) any later version, as published by the Free Software Foundation.
//
// You can also Link and Combine this program with other software covered by
// the terms of any of the Open Source Initiative approved licenses and Convey
// the resulting work. Corresponding source of such a combination shall include
// the source code for all other software used.
//
// This program is distributed WITHOUT ANY WARRANTY; without even the implied
// warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
//
// See COPYING file for full licensing terms.
// Package xbytes provides additional utilities for working with byte slices
package xbytes
import (
"bytes"
)
// ContainsByte is like bytes.ContainsRune but a bit faster
func ContainsByte(s []byte, c byte) bool {
return bytes.IndexByte(s, c) >= 0
}
......@@ -36,7 +36,7 @@ import (
"strconv"
"unicode/utf8"
"../xslice"
"../xbytes"
"lab.nexedi.com/kirr/go123/mem"
)
......@@ -127,7 +127,7 @@ func (b *Buffer) Cb(c byte) *Buffer {
// AppendRune appends to b UTF-8 encoding of r
func AppendRune(b []byte, r rune) []byte {
l := len(b)
b = xslice.Grow(b, utf8.UTFMax)
b = xbytes.Grow(b, utf8.UTFMax)
n := utf8.EncodeRune(b[l:], r)
return b[:l+n]
}
......@@ -160,7 +160,7 @@ func (b *Buffer) X(i int) *Buffer {
func AppendHex(b []byte, x []byte) []byte {
lx := hex.EncodedLen(len(x))
lb := len(b)
b = xslice.Grow(b, lx)
b = xbytes.Grow(b, lx)
hex.Encode(b[lb:], x)
return b
}
......@@ -182,7 +182,7 @@ func (b *Buffer) Xs(x string) *Buffer {
func AppendHex016(b []byte, x uint64) []byte {
// like sprintf("%016x") but faster and less allocations
l := len(b)
b = xslice.Grow(b, 16)
b = xbytes.Grow(b, 16)
bb := b[l:]
for i := 15; i >= 0; i-- {
bb[i] = hexdigits[x & 0xf]
......
......@@ -20,18 +20,13 @@
package xfmt
import (
"bytes"
"strconv"
"unicode/utf8"
"lab.nexedi.com/kirr/go123/mem"
"../xbytes"
)
// bytesContainsByte is like bytes.ContainsRune but a bit faster
func bytesContainsByte(s []byte, c byte) bool {
return bytes.IndexByte(s, c) >= 0
}
// AppendQuotePy appends to buf Python quoting of s
func AppendQuotePy(buf []byte, s string) []byte {
return AppendQuotePyBytes(buf, mem.Bytes(s))
......@@ -42,7 +37,7 @@ func AppendQuotePyBytes(buf, b []byte) []byte {
// smartquotes: choose ' or " as quoting character
// https://github.com/python/cpython/blob/v2.7.13-116-g1aa1803b3d/Objects/stringobject.c#L947
quote := byte('\'')
if bytesContainsByte(b, '\'') && !bytesContainsByte(b, '"') {
if xbytes.ContainsByte(b, '\'') && !xbytes.ContainsByte(b, '"') {
quote = '"'
}
......
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