Commit 2789db4e authored by Kirill Smelkov's avatar Kirill Smelkov

xbytes: Fix docstrings, so that it renders more well in godoc.

parent 7a476082
// Copyright (C) 2017 Nexedi SA and Contributors.
// Kirill Smelkov <kirr@nexedi.com>
// Copyright (C) 2017-2018 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
......@@ -17,7 +17,7 @@
// See COPYING file for full licensing terms.
// See https://www.nexedi.com/licensing for rationale and options.
// (re)allocation routines for []byte
// (re)allocation routines for []byte.
package xbytes
......@@ -26,6 +26,7 @@ import (
)
// Grow increases length of byte slice by n elements.
//
// If there is not enough capacity the slice is reallocated and copied.
// The memory for grown elements is not initialized.
func Grow(b []byte, n int) []byte {
......@@ -39,7 +40,8 @@ func Grow(b []byte, n int) []byte {
return bb
}
// MakeRoom makes sure cap(b) - len(b) >= n
// MakeRoom makes sure cap(b) - len(b) >= n.
//
// If there is not enough capacity the slice is reallocated and copied.
// Length of the slice remains unchanged.
func MakeRoom(b []byte, n int) []byte {
......@@ -53,8 +55,9 @@ func MakeRoom(b []byte, n int) []byte {
return bb
}
// Resize resized byte slice to be of length n.
// If slice length is increased and there is not enough capacity the slice is reallocated and copied.
// Resize resizes byte slice to be of length n.
//
// If slice length is increased and there is not enough capacity, the slice is reallocated and copied.
// The memory for grown elements, if any, is not initialized.
func Resize(b []byte, n int) []byte {
if cap(b) >= n {
......@@ -68,16 +71,17 @@ func Resize(b []byte, n int) []byte {
// Realloc resizes byte slice to be of length n not preserving content.
// If slice length is increased and there is not enough capacity the slice is reallocated but not copied.
//
// If slice length is increased and there is not enough capacity, the slice is reallocated but not copied.
// The memory for all elements becomes uninitialized.
//
// NOTE semantic is different from C realloc(3) where content is preserved
// NOTE use Resize when you need to preserve slice content
// NOTE semantic is different from C realloc(3) where content is preserved.
// NOTE use Resize when you need to preserve slice content.
func Realloc(b []byte, n int) []byte {
return Realloc64(b, int64(n))
}
// Realloc64 is the same as Realloc but for size typed as int64
// Realloc64 is the same as Realloc but for size typed as int64.
func Realloc64(b []byte, n int64) []byte {
if int64(cap(b)) >= n {
return b[:n]
......
// Copyright (C) 2017 Nexedi SA and Contributors.
// Kirill Smelkov <kirr@nexedi.com>
// Copyright (C) 2017-2018 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
......@@ -17,14 +17,14 @@
// See COPYING file for full licensing terms.
// See https://www.nexedi.com/licensing for rationale and options.
// Package xbytes provides additional utilities for working with byte slices
// Package xbytes provides additional utilities for working with byte slices.
package xbytes
import (
"bytes"
)
// ContainsByte is like bytes.ContainsRune but a bit faster
// ContainsByte is like bytes.ContainsRune but a bit faster.
func ContainsByte(s []byte, c byte) bool {
return bytes.IndexByte(s, c) >= 0
}
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