Commit f1278d15 authored by Kirill Smelkov's avatar Kirill Smelkov

.

parent 0332d46d
...@@ -32,8 +32,8 @@ import ( ...@@ -32,8 +32,8 @@ import (
"../../../../storage/fs1" "../../../../storage/fs1"
"../../../../xcommon/xbufio" "../../../../xcommon/xbufio"
"../../../../xcommon/xbytes"
"../../../../xcommon/xfmt" "../../../../xcommon/xfmt"
"../../../../xcommon/xslice"
) )
...@@ -105,7 +105,7 @@ func fsTail(w io.Writer, path string, ntxn int) (err error) { ...@@ -105,7 +105,7 @@ func fsTail(w io.Writer, path string, ntxn int) (err error) {
// read raw data inside transaction record // read raw data inside transaction record
dataLen := txnh.DataLen() dataLen := txnh.DataLen()
data = xslice.Realloc64(data, dataLen) data = xbytes.Realloc64(data, dataLen)
_, err = fSeq.ReadAt(data, txnh.DataPos()) _, err = fSeq.ReadAt(data, txnh.DataPos())
if err != nil { if err != nil {
// XXX -> txnh.Err(...) ? // XXX -> txnh.Err(...) ?
......
...@@ -24,7 +24,7 @@ import ( ...@@ -24,7 +24,7 @@ import (
"../../zodb" "../../zodb"
"../../xcommon/xbufio" "../../xcommon/xbufio"
"../../xcommon/xslice" "../../xcommon/xbytes"
) )
// FileStorage is a ZODB storage which stores data in simple append-only file // FileStorage is a ZODB storage which stores data in simple append-only file
...@@ -194,7 +194,7 @@ func (txnh *TxnHeader) DataLen() int64 { ...@@ -194,7 +194,7 @@ func (txnh *TxnHeader) DataLen() int64 {
func (txnh *TxnHeader) CloneFrom(txnh2 *TxnHeader) { func (txnh *TxnHeader) CloneFrom(txnh2 *TxnHeader) {
workMem := txnh.workMem workMem := txnh.workMem
lwork2 := len(txnh2.workMem) lwork2 := len(txnh2.workMem)
workMem = xslice.Realloc(workMem, lwork2) workMem = xbytes.Realloc(workMem, lwork2)
*txnh = *txnh2 *txnh = *txnh2
// now unshare slices // now unshare slices
txnh.workMem = workMem txnh.workMem = workMem
...@@ -311,7 +311,7 @@ func (txnh *TxnHeader) Load(r io.ReaderAt /* *os.File */, pos int64, flags TxnLo ...@@ -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) // 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) // NOTE we encode each x string length into cap(x)
// and set len(x) = 0 to indicate x is not loaded yet // 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 ...@@ -646,7 +646,7 @@ func (dh *DataHeader) LoadData(r io.ReaderAt /* *os.File */, buf *[]byte) error
} }
// now read actual data // now read actual data
*buf = xslice.Realloc64(*buf, dh.DataLen) *buf = xbytes.Realloc64(*buf, dh.DataLen)
_, err := r.ReadAt(*buf, dh.Pos + DataHeaderSize) _, err := r.ReadAt(*buf, dh.Pos + DataHeaderSize)
if err != nil { if err != nil {
return dh.err("read data", noEOF(err)) // XXX recheck return dh.err("read data", noEOF(err)) // XXX recheck
......
...@@ -15,9 +15,9 @@ ...@@ -15,9 +15,9 @@
// //
// See COPYING file for full licensing terms. // See COPYING file for full licensing terms.
// Package xbytes provides addons to std package bytes // (re)allocation routines for []byte
// Package xbytes provides additional utilities for working with (XXX byte) slices
package xslice package xbytes
import ( import (
"../xmath" "../xmath"
......
...@@ -15,7 +15,7 @@ ...@@ -15,7 +15,7 @@
// //
// See COPYING file for full licensing terms. // See COPYING file for full licensing terms.
package xslice package xbytes
import ( import (
"bytes" "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 ( ...@@ -36,7 +36,7 @@ import (
"strconv" "strconv"
"unicode/utf8" "unicode/utf8"
"../xslice" "../xbytes"
"lab.nexedi.com/kirr/go123/mem" "lab.nexedi.com/kirr/go123/mem"
) )
...@@ -127,7 +127,7 @@ func (b *Buffer) Cb(c byte) *Buffer { ...@@ -127,7 +127,7 @@ func (b *Buffer) Cb(c byte) *Buffer {
// AppendRune appends to b UTF-8 encoding of r // AppendRune appends to b UTF-8 encoding of r
func AppendRune(b []byte, r rune) []byte { func AppendRune(b []byte, r rune) []byte {
l := len(b) l := len(b)
b = xslice.Grow(b, utf8.UTFMax) b = xbytes.Grow(b, utf8.UTFMax)
n := utf8.EncodeRune(b[l:], r) n := utf8.EncodeRune(b[l:], r)
return b[:l+n] return b[:l+n]
} }
...@@ -160,7 +160,7 @@ func (b *Buffer) X(i int) *Buffer { ...@@ -160,7 +160,7 @@ func (b *Buffer) X(i int) *Buffer {
func AppendHex(b []byte, x []byte) []byte { func AppendHex(b []byte, x []byte) []byte {
lx := hex.EncodedLen(len(x)) lx := hex.EncodedLen(len(x))
lb := len(b) lb := len(b)
b = xslice.Grow(b, lx) b = xbytes.Grow(b, lx)
hex.Encode(b[lb:], x) hex.Encode(b[lb:], x)
return b return b
} }
...@@ -182,7 +182,7 @@ func (b *Buffer) Xs(x string) *Buffer { ...@@ -182,7 +182,7 @@ func (b *Buffer) Xs(x string) *Buffer {
func AppendHex016(b []byte, x uint64) []byte { func AppendHex016(b []byte, x uint64) []byte {
// like sprintf("%016x") but faster and less allocations // like sprintf("%016x") but faster and less allocations
l := len(b) l := len(b)
b = xslice.Grow(b, 16) b = xbytes.Grow(b, 16)
bb := b[l:] bb := b[l:]
for i := 15; i >= 0; i-- { for i := 15; i >= 0; i-- {
bb[i] = hexdigits[x & 0xf] bb[i] = hexdigits[x & 0xf]
......
...@@ -20,18 +20,13 @@ ...@@ -20,18 +20,13 @@
package xfmt package xfmt
import ( import (
"bytes"
"strconv" "strconv"
"unicode/utf8" "unicode/utf8"
"lab.nexedi.com/kirr/go123/mem" "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 // AppendQuotePy appends to buf Python quoting of s
func AppendQuotePy(buf []byte, s string) []byte { func AppendQuotePy(buf []byte, s string) []byte {
return AppendQuotePyBytes(buf, mem.Bytes(s)) return AppendQuotePyBytes(buf, mem.Bytes(s))
...@@ -42,7 +37,7 @@ func AppendQuotePyBytes(buf, b []byte) []byte { ...@@ -42,7 +37,7 @@ func AppendQuotePyBytes(buf, b []byte) []byte {
// smartquotes: choose ' or " as quoting character // smartquotes: choose ' or " as quoting character
// https://github.com/python/cpython/blob/v2.7.13-116-g1aa1803b3d/Objects/stringobject.c#L947 // https://github.com/python/cpython/blob/v2.7.13-116-g1aa1803b3d/Objects/stringobject.c#L947
quote := byte('\'') quote := byte('\'')
if bytesContainsByte(b, '\'') && !bytesContainsByte(b, '"') { if xbytes.ContainsByte(b, '\'') && !xbytes.ContainsByte(b, '"') {
quote = '"' 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