aboutsummaryrefslogtreecommitdiff
path: root/src/bytes
diff options
context:
space:
mode:
authorFilippo Valsorda <filippo@golang.org>2018-09-06 13:25:27 -0400
committerFilippo Valsorda <filippo@golang.org>2018-09-06 13:25:27 -0400
commit4d1aa482b8754c081d8f3f6b39fe61dd2e6504fc (patch)
treeb12a76ad02035d1206d09a7aa14a6cda0c411c3c /src/bytes
parent7eb1677c01c3decc510270d532ed69d0bf42bffa (diff)
parent3e5b5d69dcdb82494f550049986426d84dd6b8f8 (diff)
downloadgo-4d1aa482b8754c081d8f3f6b39fe61dd2e6504fc.tar.xz
[dev.boringcrypto] all: merge master into dev.boringcrypto
Change-Id: Ia8ddd4e52dcfe87f9daef2edd37c8155fcae7f5a
Diffstat (limited to 'src/bytes')
-rw-r--r--src/bytes/buffer.go6
-rw-r--r--src/bytes/buffer_test.go2
-rw-r--r--src/bytes/bytes.go6
-rw-r--r--src/bytes/compare_test.go15
-rw-r--r--src/bytes/example_test.go8
5 files changed, 28 insertions, 9 deletions
diff --git a/src/bytes/buffer.go b/src/bytes/buffer.go
index a2eca2ed12..14c5bc38d6 100644
--- a/src/bytes/buffer.go
+++ b/src/bytes/buffer.go
@@ -441,9 +441,9 @@ func (b *Buffer) ReadString(delim byte) (line string, err error) {
// NewBuffer creates and initializes a new Buffer using buf as its
// initial contents. The new Buffer takes ownership of buf, and the
// caller should not use buf after this call. NewBuffer is intended to
-// prepare a Buffer to read existing data. It can also be used to size
-// the internal buffer for writing. To do that, buf should have the
-// desired capacity but a length of zero.
+// prepare a Buffer to read existing data. It can also be used to set
+// the initial size of the internal buffer for writing. To do that,
+// buf should have the desired capacity but a length of zero.
//
// In most cases, new(Buffer) (or just declaring a Buffer variable) is
// sufficient to initialize a Buffer.
diff --git a/src/bytes/buffer_test.go b/src/bytes/buffer_test.go
index acbe5ca0c4..6e9d6952a5 100644
--- a/src/bytes/buffer_test.go
+++ b/src/bytes/buffer_test.go
@@ -293,7 +293,7 @@ func TestReadFromPanicReader(t *testing.T) {
}
check(t, "TestReadFromPanicReader (1)", &buf, "")
- // Confirm that when Reader panics, the emtpy buffer remains empty
+ // Confirm that when Reader panics, the empty buffer remains empty
var buf2 Buffer
defer func() {
recover()
diff --git a/src/bytes/bytes.go b/src/bytes/bytes.go
index 437a6e12df..77a7ce98e0 100644
--- a/src/bytes/bytes.go
+++ b/src/bytes/bytes.go
@@ -489,19 +489,19 @@ func ToTitle(s []byte) []byte { return Map(unicode.ToTitle, s) }
// ToUpperSpecial treats s as UTF-8-encoded bytes and returns a copy with all the Unicode letters mapped to their
// upper case, giving priority to the special casing rules.
func ToUpperSpecial(c unicode.SpecialCase, s []byte) []byte {
- return Map(func(r rune) rune { return c.ToUpper(r) }, s)
+ return Map(c.ToUpper, s)
}
// ToLowerSpecial treats s as UTF-8-encoded bytes and returns a copy with all the Unicode letters mapped to their
// lower case, giving priority to the special casing rules.
func ToLowerSpecial(c unicode.SpecialCase, s []byte) []byte {
- return Map(func(r rune) rune { return c.ToLower(r) }, s)
+ return Map(c.ToLower, s)
}
// ToTitleSpecial treats s as UTF-8-encoded bytes and returns a copy with all the Unicode letters mapped to their
// title case, giving priority to the special casing rules.
func ToTitleSpecial(c unicode.SpecialCase, s []byte) []byte {
- return Map(func(r rune) rune { return c.ToTitle(r) }, s)
+ return Map(c.ToTitle, s)
}
// isSeparator reports whether the rune could mark a word boundary.
diff --git a/src/bytes/compare_test.go b/src/bytes/compare_test.go
index 35088a1b2e..3e33c27c9c 100644
--- a/src/bytes/compare_test.go
+++ b/src/bytes/compare_test.go
@@ -6,6 +6,7 @@ package bytes_test
import (
. "bytes"
+ "internal/testenv"
"testing"
)
@@ -58,10 +59,20 @@ func TestCompareIdenticalSlice(t *testing.T) {
}
func TestCompareBytes(t *testing.T) {
- n := 128
+ lengths := make([]int, 0) // lengths to test in ascending order
+ for i := 0; i <= 128; i++ {
+ lengths = append(lengths, i)
+ }
+ lengths = append(lengths, 256, 512, 1024, 1333, 4095, 4096, 4097)
+
+ if !testing.Short() || testenv.Builder() != "" {
+ lengths = append(lengths, 65535, 65536, 65537, 99999)
+ }
+
+ n := lengths[len(lengths)-1]
a := make([]byte, n+1)
b := make([]byte, n+1)
- for len := 0; len < 128; len++ {
+ for _, len := range lengths {
// randomish but deterministic data. No 0 or 255.
for i := 0; i < len; i++ {
a[i] = byte(1 + 31*i%254)
diff --git a/src/bytes/example_test.go b/src/bytes/example_test.go
index 5b7a46058f..4d5cdfa280 100644
--- a/src/bytes/example_test.go
+++ b/src/bytes/example_test.go
@@ -39,6 +39,14 @@ func ExampleBuffer_Grow() {
// Output: "64 bytes or fewer"
}
+func ExampleBuffer_Len() {
+ var b bytes.Buffer
+ b.Grow(64)
+ b.Write([]byte("abcde"))
+ fmt.Printf("%d", b.Len())
+ // Output: 5
+}
+
func ExampleCompare() {
// Interpret Compare's result by comparing it to zero.
var a, b []byte