Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
go123
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
go123
Commits
2789db4e
Commit
2789db4e
authored
Jul 06, 2018
by
Kirill Smelkov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
xbytes: Fix docstrings, so that it renders more well in godoc.
parent
7a476082
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
18 additions
and
14 deletions
+18
-14
xbytes/alloc.go
xbytes/alloc.go
+14
-10
xbytes/bytes.go
xbytes/bytes.go
+4
-4
No files found.
xbytes/alloc.go
View file @
2789db4e
// Copyright (C) 2017 Nexedi SA and Contributors.
// 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
...
...
@@ -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
]
...
...
xbytes/bytes.go
View file @
2789db4e
// Copyright (C) 2017 Nexedi SA and Contributors.
// 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
...
...
@@ -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
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment