diff options
author | Ian Lance Taylor <ian@gcc.gnu.org> | 2015-10-31 00:59:47 +0000 |
---|---|---|
committer | Ian Lance Taylor <ian@gcc.gnu.org> | 2015-10-31 00:59:47 +0000 |
commit | af146490bb04205107cb23e301ec7a8ff927b5fc (patch) | |
tree | 13beeaed3698c61903fe93fb1ce70bd9b18d4e7f /libgo/go/bytes | |
parent | 725e1be3406315d9bcc8195d7eef0a7082b3c7cc (diff) | |
download | gcc-af146490bb04205107cb23e301ec7a8ff927b5fc.zip gcc-af146490bb04205107cb23e301ec7a8ff927b5fc.tar.gz gcc-af146490bb04205107cb23e301ec7a8ff927b5fc.tar.bz2 |
runtime: Remove now unnecessary pad field from ParFor.
It is not needed due to the removal of the ctx field.
Reviewed-on: https://go-review.googlesource.com/16525
From-SVN: r229616
Diffstat (limited to 'libgo/go/bytes')
-rw-r--r-- | libgo/go/bytes/buffer.go | 4 | ||||
-rw-r--r-- | libgo/go/bytes/buffer_test.go | 17 | ||||
-rw-r--r-- | libgo/go/bytes/bytes.go | 15 | ||||
-rw-r--r-- | libgo/go/bytes/bytes_decl.go | 2 | ||||
-rw-r--r-- | libgo/go/bytes/bytes_test.go | 17 | ||||
-rw-r--r-- | libgo/go/bytes/compare_test.go | 3 | ||||
-rw-r--r-- | libgo/go/bytes/export_test.go | 4 | ||||
-rw-r--r-- | libgo/go/bytes/reader.go | 6 | ||||
-rw-r--r-- | libgo/go/bytes/reader_test.go | 12 |
9 files changed, 73 insertions, 7 deletions
diff --git a/libgo/go/bytes/buffer.go b/libgo/go/bytes/buffer.go index 46ca1d5..4db9386 100644 --- a/libgo/go/bytes/buffer.go +++ b/libgo/go/bytes/buffer.go @@ -56,6 +56,10 @@ func (b *Buffer) String() string { // b.Len() == len(b.Bytes()). func (b *Buffer) Len() int { return len(b.buf) - b.off } +// Cap returns the capacity of the buffer's underlying byte slice, that is, the +// total space allocated for the buffer's data. +func (b *Buffer) Cap() int { return cap(b.buf) } + // Truncate discards all but the first n unread bytes from the buffer. // It panics if n is negative or greater than the length of the buffer. func (b *Buffer) Truncate(n int) { diff --git a/libgo/go/bytes/buffer_test.go b/libgo/go/bytes/buffer_test.go index 75145b0..7de17ae 100644 --- a/libgo/go/bytes/buffer_test.go +++ b/libgo/go/bytes/buffer_test.go @@ -231,6 +231,23 @@ func TestMixedReadsAndWrites(t *testing.T) { empty(t, "TestMixedReadsAndWrites (2)", &buf, s, make([]byte, buf.Len())) } +func TestCapWithPreallocatedSlice(t *testing.T) { + buf := NewBuffer(make([]byte, 10)) + n := buf.Cap() + if n != 10 { + t.Errorf("expected 10, got %d", n) + } +} + +func TestCapWithSliceAndWrittenData(t *testing.T) { + buf := NewBuffer(make([]byte, 0, 10)) + buf.Write([]byte("test")) + n := buf.Cap() + if n != 10 { + t.Errorf("expected 10, got %d", n) + } +} + func TestNil(t *testing.T) { var b *Buffer if b.String() != "<nil>" { diff --git a/libgo/go/bytes/bytes.go b/libgo/go/bytes/bytes.go index 7634707..b868240 100644 --- a/libgo/go/bytes/bytes.go +++ b/libgo/go/bytes/bytes.go @@ -23,7 +23,7 @@ func equalPortable(a, b []byte) bool { return true } -// explode splits s into a slice of UTF-8 sequences, one per Unicode character (still slices of bytes), +// 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 { if n <= 0 { @@ -47,6 +47,7 @@ func explode(s []byte, n int) [][]byte { } // Count counts the number of non-overlapping instances of sep in s. +// If sep is an empty slice, Count returns 1 + the number of Unicode code points in s. func Count(s, sep []byte) int { n := len(sep) if n == 0 { @@ -137,6 +138,16 @@ func LastIndex(s, sep []byte) int { return -1 } +// LastIndexByte returns the index of the last instance of c in s, or -1 if c is not present in s. +func LastIndexByte(s []byte, c byte) int { + for i := len(s) - 1; i >= 0; i-- { + if s[i] == c { + return i + } + } + return -1 +} + // IndexRune interprets s as a sequence of UTF-8-encoded Unicode code points. // It returns the byte index of the first occurrence in s of the given rune. // It returns -1 if rune is not present in s. @@ -442,7 +453,7 @@ func isSeparator(r rune) bool { // Title returns a copy of s with all Unicode letters that begin words // mapped to their title case. // -// BUG: The rule Title uses for word boundaries does not handle Unicode punctuation properly. +// BUG(rsc): The rule Title uses for word boundaries does not handle Unicode punctuation properly. func Title(s []byte) []byte { // Use a closure here to remember state. // Hackish but effective. Depends on Map scanning in order and calling diff --git a/libgo/go/bytes/bytes_decl.go b/libgo/go/bytes/bytes_decl.go index 617d748..b453f21 100644 --- a/libgo/go/bytes/bytes_decl.go +++ b/libgo/go/bytes/bytes_decl.go @@ -21,4 +21,4 @@ func Equal(a, b []byte) bool // ../runtime/asm_$GOARCH.s // 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 // ../runtime/noasm_arm.goc or ../runtime/asm_{386,amd64}.s +func Compare(a, b []byte) int // ../runtime/noasm.go or ../runtime/asm_{386,amd64}.s diff --git a/libgo/go/bytes/bytes_test.go b/libgo/go/bytes/bytes_test.go index 980c41d..6245e48 100644 --- a/libgo/go/bytes/bytes_test.go +++ b/libgo/go/bytes/bytes_test.go @@ -265,6 +265,23 @@ func TestIndexByte(t *testing.T) { } } +func TestLastIndexByte(t *testing.T) { + testCases := []BinOpTest{ + {"", "q", -1}, + {"abcdef", "q", -1}, + {"abcdefabcdef", "a", len("abcdef")}, // something in the middle + {"abcdefabcdef", "f", len("abcdefabcde")}, // last byte + {"zabcdefabcdef", "z", 0}, // first byte + {"a☺b☻c☹d", "b", len("a☺")}, // non-ascii + } + for _, test := range testCases { + actual := LastIndexByte([]byte(test.a), test.b[0]) + if actual != test.i { + t.Errorf("LastIndexByte(%q,%c) = %v; want %v", test.a, test.b[0], actual, test.i) + } + } +} + // test a larger buffer with different sizes and alignments func TestIndexByteBig(t *testing.T) { var n = 1024 diff --git a/libgo/go/bytes/compare_test.go b/libgo/go/bytes/compare_test.go index 6352237..f2d81d5 100644 --- a/libgo/go/bytes/compare_test.go +++ b/libgo/go/bytes/compare_test.go @@ -17,6 +17,8 @@ var compareTests = []struct { {[]byte("a"), []byte(""), 1}, {[]byte(""), []byte("a"), -1}, {[]byte("abc"), []byte("abc"), 0}, + {[]byte("abd"), []byte("abc"), 1}, + {[]byte("abc"), []byte("abd"), -1}, {[]byte("ab"), []byte("abc"), -1}, {[]byte("abc"), []byte("ab"), 1}, {[]byte("x"), []byte("ab"), 1}, @@ -27,6 +29,7 @@ var compareTests = []struct { {[]byte("abcdefgh"), []byte("abcdefgh"), 0}, {[]byte("abcdefghi"), []byte("abcdefghi"), 0}, {[]byte("abcdefghi"), []byte("abcdefghj"), -1}, + {[]byte("abcdefghj"), []byte("abcdefghi"), 1}, // nil tests {nil, nil, 0}, {[]byte(""), nil, 0}, diff --git a/libgo/go/bytes/export_test.go b/libgo/go/bytes/export_test.go index 3b915d5..f61523e 100644 --- a/libgo/go/bytes/export_test.go +++ b/libgo/go/bytes/export_test.go @@ -7,7 +7,3 @@ package bytes // Export func for testing var IndexBytePortable = indexBytePortable var EqualPortable = equalPortable - -func (b *Buffer) Cap() int { - return cap(b.buf) -} diff --git a/libgo/go/bytes/reader.go b/libgo/go/bytes/reader.go index d2d40fa..b89d154 100644 --- a/libgo/go/bytes/reader.go +++ b/libgo/go/bytes/reader.go @@ -29,6 +29,12 @@ func (r *Reader) Len() int { return int(int64(len(r.s)) - r.i) } +// Size returns the original length of the underlying byte slice. +// Size is the number of bytes available for reading via ReadAt. +// The returned value is always the same and is not affected by calls +// to any other method. +func (r *Reader) Size() int64 { return int64(len(r.s)) } + func (r *Reader) Read(b []byte) (n int, err error) { if len(b) == 0 { return 0, nil diff --git a/libgo/go/bytes/reader_test.go b/libgo/go/bytes/reader_test.go index d3dce53..b929a28 100644 --- a/libgo/go/bytes/reader_test.go +++ b/libgo/go/bytes/reader_test.go @@ -244,3 +244,15 @@ func TestReaderCopyNothing(t *testing.T) { t.Errorf("behavior differs: with = %#v; without: %#v", with, withOut) } } + +// tests that Len is affected by reads, but Size is not. +func TestReaderLenSize(t *testing.T) { + r := NewReader([]byte("abc")) + io.CopyN(ioutil.Discard, r, 1) + if r.Len() != 2 { + t.Errorf("Len = %d; want 2", r.Len()) + } + if r.Size() != 3 { + t.Errorf("Size = %d; want 3", r.Size()) + } +} |