aboutsummaryrefslogtreecommitdiff
path: root/src/bytes
diff options
context:
space:
mode:
authorKeith Randall <khr@google.com>2018-11-05 11:00:01 -0800
committerKeith Randall <khr@golang.org>2018-11-08 20:52:47 +0000
commitad4a58e31501bce5de2aad90a620eaecdc1eecb8 (patch)
treee08af15fd1be09d25d23e0b18ea9e8dc9f2d2c80 /src/bytes
parent742be070b6109d32a5e91d13a75542aefc892ee1 (diff)
downloadgo-ad4a58e31501bce5de2aad90a620eaecdc1eecb8.tar.gz
go-ad4a58e31501bce5de2aad90a620eaecdc1eecb8.zip
strings,bytes: use inlineable function trampolines instead of linkname
Cleans things up quite a bit. There's still a few more, like runtime.cmpstring, which might also be worth fixing. Change-Id: Ide18dd621efc129cc686db223f47fa0b044b5580 Reviewed-on: https://go-review.googlesource.com/c/148578 Run-TryBot: Keith Randall <khr@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Austin Clements <austin@google.com>
Diffstat (limited to 'src/bytes')
-rw-r--r--src/bytes/bytes.go19
-rw-r--r--src/bytes/bytes_decl.go24
2 files changed, 19 insertions, 24 deletions
diff --git a/src/bytes/bytes.go b/src/bytes/bytes.go
index 6492db088a..daf4a32f26 100644
--- a/src/bytes/bytes.go
+++ b/src/bytes/bytes.go
@@ -12,6 +12,13 @@ import (
"unicode/utf8"
)
+// Equal returns a boolean reporting whether a and b
+// are the same length and contain the same bytes.
+// A nil argument is equivalent to an empty slice.
+func Equal(a, b []byte) bool {
+ return bytealg.Equal(a, b)
+}
+
func equalPortable(a, b []byte) bool {
if len(a) != len(b) {
return false
@@ -24,6 +31,13 @@ func equalPortable(a, b []byte) bool {
return true
}
+// Compare returns an integer comparing two byte slices lexicographically.
+// The result will be 0 if a==b, -1 if a < b, and +1 if a > b.
+// A nil argument is equivalent to an empty slice.
+func Compare(a, b []byte) int {
+ return bytealg.Compare(a, b)
+}
+
// explode splits s into a slice of UTF-8 sequences, one per Unicode code point (still slices of bytes),
// up to a maximum of n byte slices. Invalid UTF-8 sequences are chopped into individual bytes.
func explode(s []byte, n int) [][]byte {
@@ -83,6 +97,11 @@ func ContainsRune(b []byte, r rune) bool {
return IndexRune(b, r) >= 0
}
+// IndexByte returns the index of the first instance of c in b, or -1 if c is not present in b.
+func IndexByte(b []byte, c byte) int {
+ return bytealg.IndexByte(b, c)
+}
+
func indexBytePortable(s []byte, c byte) int {
for i, b := range s {
if b == c {
diff --git a/src/bytes/bytes_decl.go b/src/bytes/bytes_decl.go
deleted file mode 100644
index af0f8b179f..0000000000
--- a/src/bytes/bytes_decl.go
+++ /dev/null
@@ -1,24 +0,0 @@
-// Copyright 2010 The Go Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style
-// license that can be found in the LICENSE file.
-
-package bytes
-
-//go:noescape
-
-// IndexByte returns the index of the first instance of c in b, or -1 if c is not present in b.
-func IndexByte(b []byte, c byte) int // in internal/bytealg
-
-//go:noescape
-
-// Equal returns a boolean reporting whether a and b
-// are the same length and contain the same bytes.
-// A nil argument is equivalent to an empty slice.
-func Equal(a, b []byte) bool // in internal/bytealg
-
-//go:noescape
-
-// Compare returns an integer comparing two byte slices lexicographically.
-// The result will be 0 if a==b, -1 if a < b, and +1 if a > b.
-// A nil argument is equivalent to an empty slice.
-func Compare(a, b []byte) int // in internal/bytealg