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. // Copyright (C) 2017-2018 Nexedi SA and Contributors.
// Kirill Smelkov <kirr@nexedi.com> // Kirill Smelkov <kirr@nexedi.com>
// //
// This program is free software: you can Use, Study, Modify and Redistribute // 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 // it under the terms of the GNU General Public License version 3, or (at your
...@@ -17,7 +17,7 @@ ...@@ -17,7 +17,7 @@
// See COPYING file for full licensing terms. // See COPYING file for full licensing terms.
// See https://www.nexedi.com/licensing for rationale and options. // See https://www.nexedi.com/licensing for rationale and options.
// (re)allocation routines for []byte // (re)allocation routines for []byte.
package xbytes package xbytes
...@@ -26,6 +26,7 @@ import ( ...@@ -26,6 +26,7 @@ import (
) )
// Grow increases length of byte slice by n elements. // Grow increases length of byte slice by n elements.
//
// If there is not enough capacity the slice is reallocated and copied. // If there is not enough capacity the slice is reallocated and copied.
// The memory for grown elements is not initialized. // The memory for grown elements is not initialized.
func Grow(b []byte, n int) []byte { func Grow(b []byte, n int) []byte {
...@@ -39,7 +40,8 @@ func Grow(b []byte, n int) []byte { ...@@ -39,7 +40,8 @@ func Grow(b []byte, n int) []byte {
return bb 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. // If there is not enough capacity the slice is reallocated and copied.
// Length of the slice remains unchanged. // Length of the slice remains unchanged.
func MakeRoom(b []byte, n int) []byte { func MakeRoom(b []byte, n int) []byte {
...@@ -53,8 +55,9 @@ func MakeRoom(b []byte, n int) []byte { ...@@ -53,8 +55,9 @@ func MakeRoom(b []byte, n int) []byte {
return bb return bb
} }
// Resize resized byte slice to be of length n. // 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. //
// 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. // The memory for grown elements, if any, is not initialized.
func Resize(b []byte, n int) []byte { func Resize(b []byte, n int) []byte {
if cap(b) >= n { if cap(b) >= n {
...@@ -68,16 +71,17 @@ func Resize(b []byte, n int) []byte { ...@@ -68,16 +71,17 @@ func Resize(b []byte, n int) []byte {
// Realloc resizes byte slice to be of length n not preserving content. // 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. // The memory for all elements becomes uninitialized.
// //
// NOTE semantic is different from C realloc(3) where content is preserved // NOTE semantic is different from C realloc(3) where content is preserved.
// NOTE use Resize when you need to preserve slice content // NOTE use Resize when you need to preserve slice content.
func Realloc(b []byte, n int) []byte { func Realloc(b []byte, n int) []byte {
return Realloc64(b, int64(n)) 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 { func Realloc64(b []byte, n int64) []byte {
if int64(cap(b)) >= n { if int64(cap(b)) >= n {
return b[:n] return b[:n]
......
// Copyright (C) 2017 Nexedi SA and Contributors. // Copyright (C) 2017-2018 Nexedi SA and Contributors.
// Kirill Smelkov <kirr@nexedi.com> // Kirill Smelkov <kirr@nexedi.com>
// //
// This program is free software: you can Use, Study, Modify and Redistribute // 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 // it under the terms of the GNU General Public License version 3, or (at your
...@@ -17,14 +17,14 @@ ...@@ -17,14 +17,14 @@
// See COPYING file for full licensing terms. // See COPYING file for full licensing terms.
// See https://www.nexedi.com/licensing for rationale and options. // 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 package xbytes
import ( import (
"bytes" "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 { func ContainsByte(s []byte, c byte) bool {
return bytes.IndexByte(s, c) >= 0 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