aboutsummaryrefslogtreecommitdiff
path: root/src/pkg/strings
AgeCommit message (Collapse)Author
2014-09-08build: move package sources from src/pkg to srcRuss Cox
Preparation was in CL 134570043. This CL contains only the effect of 'hg mv src/pkg/* src'. For more about the move, see golang.org/s/go14nopkg.
2014-09-01strings: use Rabin-Karp algorithm for LastIndex.Rui Ueyama
benchmark old ns/op new ns/op delta BenchmarkSingleMatch 49443 52275 +5.73% BenchmarkIndex 28.8 27.4 -4.86% BenchmarkLastIndex 14.5 14.0 -3.45% BenchmarkLastIndexHard1 3982782 2309200 -42.02% BenchmarkLastIndexHard2 3985562 2287715 -42.60% BenchmarkLastIndexHard3 3555259 2282866 -35.79% LGTM=josharian, nigeltao R=golang-codereviews, ality, josharian, bradfitz, dave, nigeltao, gobot, nightlyone CC=golang-codereviews https://golang.org/cl/102560043
2014-08-25strings, bytes: document behavior of Replace when old is emptyCaleb Spare
Fixes #8143. LGTM=r R=rsc, bradfitz, r CC=golang-codereviews https://golang.org/cl/135760043
2014-07-17strings: remove byteBitmapRui Ueyama
Previously we had a bitmap to check whether or not a byte appears in a string should be replaced. But we don't actually need a separate bitmap for that purpose. Removing the bitmap makes the code simpler. LGTM=dave, iant, nigeltao R=golang-codereviews, dave, gobot, nigeltao, iant, bradfitz, rsc CC=golang-codereviews https://golang.org/cl/110100043
2014-06-28strings: Replacer is safe for concurrent useEvan Shaw
LGTM=r R=golang-codereviews, bradfitz, r CC=golang-codereviews https://golang.org/cl/109220044
2014-06-26strings: avoid pointless slice growth in makeBenchInputHardJosh Bleecher Snyder
LGTM=ruiu R=golang-codereviews, ruiu CC=golang-codereviews https://golang.org/cl/108150043
2014-06-25strings: additional testsDave Cheney
This CL re-applies the tests added in CL 101330053 and subsequently rolled back in CL 102610043. The original author of this change was Rui Ueyama <ruiu@google.com> LGTM=r, ruiu R=ruiu, r CC=golang-codereviews https://golang.org/cl/109170043
2014-06-22undo CL 101330053 / c19c9a063fe8Rui Ueyama
sync.Pool is not supposed to be used everywhere, but is a last resort. ««« original CL description strings: use sync.Pool to cache buffer benchmark old ns/op new ns/op delta BenchmarkByteReplacerWriteString 3596 3094 -13.96% benchmark old allocs new allocs delta BenchmarkByteReplacerWriteString 1 0 -100.00% LGTM=dvyukov R=bradfitz, dave, dvyukov CC=golang-codereviews https://golang.org/cl/101330053 »»» LGTM=dave R=r, dave CC=golang-codereviews https://golang.org/cl/102610043
2014-06-21strings: use sync.Pool to cache bufferRui Ueyama
benchmark old ns/op new ns/op delta BenchmarkByteReplacerWriteString 3596 3094 -13.96% benchmark old allocs new allocs delta BenchmarkByteReplacerWriteString 1 0 -100.00% LGTM=dvyukov R=bradfitz, dave, dvyukov CC=golang-codereviews https://golang.org/cl/101330053
2014-06-20strings: speed up byteReplacer.ReplaceRui Ueyama
benchmark old ns/op new ns/op delta BenchmarkByteReplacerWriteString 7359 3661 -50.25% LGTM=dave R=golang-codereviews, dave CC=golang-codereviews https://golang.org/cl/102550043
2014-06-19strings: define byteBitmap.isSetRui Ueyama
LGTM=dave R=golang-codereviews, bradfitz, dave CC=golang-codereviews https://golang.org/cl/109090048
2014-06-19strings: reduce allocation in byteStringReplacer.WriteStringRui Ueyama
Use WriteString instead of allocating a byte slice as a buffer. This was a TODO. benchmark old ns/op new ns/op delta BenchmarkWriteString 40139 19991 -50.20% LGTM=bradfitz R=golang-codereviews, bradfitz CC=golang-codereviews https://golang.org/cl/107190044
2014-06-17strings: add fast path to ReplaceRui Ueyama
genericReplacer.lookup is called for each byte of an input string. In many (most?) cases, lookup will fail for the first byte, and it will return immediately. Adding a fast path for that case seems worth it. Benchmark on my Xeon 3.5GHz Linux box: benchmark old ns/op new ns/op delta BenchmarkGenericNoMatch 2691 774 -71.24% BenchmarkGenericMatch1 7920 8151 +2.92% BenchmarkGenericMatch2 52336 39927 -23.71% BenchmarkSingleMaxSkipping 1575 1575 +0.00% BenchmarkSingleLongSuffixFail 1429 1429 +0.00% BenchmarkSingleMatch 56228 55444 -1.39% BenchmarkByteByteNoMatch 568 568 +0.00% BenchmarkByteByteMatch 977 972 -0.51% BenchmarkByteStringMatch 1669 1687 +1.08% BenchmarkHTMLEscapeNew 422 422 +0.00% BenchmarkHTMLEscapeOld 692 670 -3.18% BenchmarkByteByteReplaces 8492 8474 -0.21% BenchmarkByteByteMap 2817 2808 -0.32% LGTM=rsc R=golang-codereviews, bradfitz, dave, rsc CC=golang-codereviews https://golang.org/cl/79200044
2014-06-11bytes, strings: optimize RepeatRui Ueyama
Call copy with as large buffer as possible to reduce the number of function calls. benchmark old ns/op new ns/op delta BenchmarkBytesRepeat 540 162 -70.00% BenchmarkStringsRepeat 563 177 -68.56% LGTM=josharian R=golang-codereviews, josharian, dave, dvyukov CC=golang-codereviews https://golang.org/cl/90550043
2014-04-25net/http, strings, bytes: fix http race, revert part of Reader behavior changeBrad Fitzpatrick
I fixed this data race regression in two ways: in net/http itself, and also partially reverting the change from https://golang.org/cl/77580046 . Previously a Read from a strings.Reader or bytes.Reader returning 0 bytes would not be a memory write. After 77580046 it was. This reverts that back in case others depended on that. Also adds tests. Fixes #7856 LGTM=ruiu, iant R=iant, ruiu CC=golang-codereviews, gri https://golang.org/cl/94740044
2014-04-21strings: fix off-by-one error in testgo1.3beta1Rui Ueyama
Previously it would panic because of out-of-bound access if s1 is longer than s2. LGTM=iant R=golang-codereviews, iant CC=golang-codereviews https://golang.org/cl/90110043
2014-04-10bytes, strings: more consistent error messagesRobert Griesemer
LGTM=bradfitz R=bradfitz CC=golang-codereviews https://golang.org/cl/86060044
2014-04-10bytes, strings: add Reader.ReadAt race testsBrad Fitzpatrick
Tests for the race detector to catch anybody trying to mutate Reader in ReadAt. LGTM=gri R=gri CC=golang-codereviews https://golang.org/cl/86700043
2014-03-28bytes, strings: allow Reader.Seek past 1<<31Brad Fitzpatrick
Fixes #7654 LGTM=rsc R=rsc, dan.kortschak CC=golang-codereviews https://golang.org/cl/81530043
2014-03-23strings: minor cleanupRui Ueyama
bi is a slice and not an array, so bi[:] does not make much sense. LGTM=bradfitz R=golang-codereviews, bradfitz CC=golang-codereviews https://golang.org/cl/79280043
2014-03-19strings, bytes: ReadAt should not mutate receiverRui Ueyama
CL 77580046 caused a data race issue with tests that assumes ReadAt does not mutate receiver. This patch partially revert CL 77580046 to fix it. LGTM=bradfitz R=golang-codereviews, bradfitz CC=golang-codereviews https://golang.org/cl/77900043
2014-03-19strings, bytes: fix Reader.UnreadRuneRui Ueyama
UnreadRune should return an error if previous operation is not ReadRune. Fixes #7579. LGTM=bradfitz R=golang-codereviews, bradfitz CC=golang-codereviews https://golang.org/cl/77580046
2013-12-20bytes, strings: improve Title test coverage by adding cases with underscore ↵Shawn Smith
and unicode line separator R=golang-codereviews, gobot, r CC=golang-codereviews https://golang.org/cl/42310045
2013-12-16strings: Add example function for IndexAnyDaniel Lidén
R=golang-dev, bradfitz CC=golang-dev https://golang.org/cl/42310044
2013-12-16strings: Add IndexFunc exampleRobin Eklind
R=golang-dev, bradfitz CC=golang-dev https://golang.org/cl/42370043
2013-12-16strings: Update Trim example.Robin Eklind
Use an input which better shows that behaviour of the function. Only leading and trailing runes are trimed, not intermediate ones. R=golang-dev, bradfitz CC=golang-dev https://golang.org/cl/42390043
2013-12-16strings: Add FieldsFunc example.Robin Eklind
R=golang-dev, dave CC=golang-dev https://golang.org/cl/42360043
2013-10-24strings: fix Replacer bug with prefix matchesBrad Fitzpatrick
singleStringReplacer had a bug where if a string was replaced at the beginning and no output had yet been produced into the temp buffer before matching ended, an invalid nil check (used as a proxy for having matched anything) meant it always returned its input. Fixes #6659 R=golang-dev, r CC=golang-dev https://golang.org/cl/16880043
2013-08-27bytes, strings: use copy in RepeatEvan Shaw
R=golang-dev, dave, bradfitz, adg CC=golang-dev https://golang.org/cl/13249043
2013-08-09strings: add test for CountPieter Droogendijk
R=golang-dev, bradfitz CC=golang-dev https://golang.org/cl/12541050
2013-08-06strings: add IndexByte benchmarkBrad Fitzpatrick
Like existing Index, IndexRune, IndexHardN, etc. R=golang-dev, khr CC=golang-dev https://golang.org/cl/12486044
2013-08-05strings: use runtime assembly for IndexByteBrad Fitzpatrick
Fixes #3751 R=golang-dev, khr CC=golang-dev https://golang.org/cl/12483043
2013-08-01strings: add IndexByte, for consistency with bytes packageBrad Fitzpatrick
I always forget which package has it. R=golang-dev, rsc CC=golang-dev https://golang.org/cl/12214044
2013-03-19bytes,strings: remove user name from BUG in commentRob Pike
R=golang-dev, dave CC=golang-dev https://golang.org/cl/7856048
2013-03-15bytes,string: move the BUG to the comment of the function it's aboutRob Pike
Avoids printing it every time we ask a question about the package from the command line. R=golang-dev, bradfitz CC=golang-dev https://golang.org/cl/7789048
2013-03-06strings: remove allocations in Split(s, "")Ewan Chou
BenchmarkSplit1 77984460 24131380 -69.06% R=golang-dev, rsc, minux.ma, dave, extemporalgenome CC=golang-dev https://golang.org/cl/7458043
2013-02-28all: fix a few more printf arg bugs found by go vetRob Pike
R=golang-dev, iant CC=golang-dev https://golang.org/cl/7413045
2013-02-20bufio: new Scanner interfaceRob Pike
Add a new, simple interface for scanning (probably textual) data, based on a new type called Scanner. It does its own internal buffering, so should be plausibly efficient even without injecting a bufio.Reader. The format of the input is defined by a "split function", by default splitting into lines. Other implemented split functions include single bytes, single runes, and space-separated words. Here's the loop to scan stdin as a file of lines: s := bufio.NewScanner(os.Stdin) for s.Scan() { fmt.Printf("%s\n", s.Bytes()) } if s.Err() != nil { log.Fatal(s.Err()) } While we're dealing with spaces, define what space means to strings.Fields. Fixes #4802. R=adg, rogpeppe, bradfitz, rsc CC=golang-dev https://golang.org/cl/7322088
2013-02-19strings: faster Count, IndexDonovan Hide
Slightly better benchmarks for when string and separator are equivalent and also less branching in inner loops. benchmark old ns/op new ns/op delta BenchmarkGenericNoMatch 3430 3442 +0.35% BenchmarkGenericMatch1 23590 22855 -3.12% BenchmarkGenericMatch2 108031 105025 -2.78% BenchmarkSingleMaxSkipping 2969 2704 -8.93% BenchmarkSingleLongSuffixFail 2826 2572 -8.99% BenchmarkSingleMatch 205268 197832 -3.62% BenchmarkByteByteNoMatch 987 921 -6.69% BenchmarkByteByteMatch 2014 1749 -13.16% BenchmarkByteStringMatch 3083 3050 -1.07% BenchmarkHTMLEscapeNew 922 915 -0.76% BenchmarkHTMLEscapeOld 1654 1570 -5.08% BenchmarkByteByteReplaces 11897 11556 -2.87% BenchmarkByteByteMap 4485 4255 -5.13% BenchmarkIndexRune 174 121 -30.46% BenchmarkIndexRuneFastPath 41 41 -0.24% BenchmarkIndex 45 44 -0.22% BenchmarkMapNoChanges 433 431 -0.46% BenchmarkIndexHard1 4015336 3316490 -17.40% BenchmarkIndexHard2 3976254 3395627 -14.60% BenchmarkIndexHard3 3973158 3378329 -14.97% BenchmarkCountHard1 4403549 3448512 -21.69% BenchmarkCountHard2 4387437 3413059 -22.21% BenchmarkCountHard3 4403891 3382661 -23.19% BenchmarkIndexTorture 28354 25864 -8.78% BenchmarkCountTorture 29625 27463 -7.30% BenchmarkFields 38752040 39169840 +1.08% BenchmarkFieldsFunc 38797765 38888060 +0.23% benchmark old MB/s new MB/s speedup BenchmarkSingleMaxSkipping 3367.07 3697.62 1.10x BenchmarkSingleLongSuffixFail 354.51 389.47 1.10x BenchmarkSingleMatch 73.07 75.82 1.04x BenchmarkFields 27.06 26.77 0.99x BenchmarkFieldsFunc 27.03 26.96 1.00x R=dave, fullung, remyoudompheng, rsc CC=golang-dev https://golang.org/cl/7350045
2013-02-17strings: better mean complexity for Count and Index.Rémy Oudompheng
The O(n+m) complexity is obtained probabilistically by using Rabin-Karp algorithm, which provides the needed complexity unless exceptional collisions occur, without memory allocation. benchmark old ns/op new ns/op delta BenchmarkIndexHard1 6532331 4045886 -38.06% BenchmarkIndexHard2 8178173 4038975 -50.61% BenchmarkIndexHard3 6973687 4042591 -42.03% BenchmarkCountHard1 6270864 4071090 -35.08% BenchmarkCountHard2 7838039 4072853 -48.04% BenchmarkCountHard3 6697828 4071964 -39.20% BenchmarkIndexTorture 2730546 28934 -98.94% BenchmarkCountTorture 2729622 29064 -98.94% Fixes #4600. R=rsc, donovanhide, remyoudompheng CC=golang-dev https://golang.org/cl/7314095
2013-02-01bytes, strings: add TrimPrefix and TrimSuffixBrad Fitzpatrick
Everybody either gets confused and thinks this is TrimLeft/TrimRight or does this by hand which gets repetitive looking. R=rsc, kevlar CC=golang-dev https://golang.org/cl/7239044
2012-11-25bytes, strings: fix Reader WriteTo return value on 0 bytes copiedBrad Fitzpatrick
Fixes #4421 R=golang-dev, dave, minux.ma, mchaten, rsc CC=golang-dev https://golang.org/cl/6855083
2012-10-30gofmt: apply gofmt -w src miscRobert Griesemer
Remove trailing whitespace in comments. No other changes. R=r CC=golang-dev https://golang.org/cl/6815053
2012-10-12bytes, strings: add (*Reader).WriteToEvan Shaw
Fixes #4031. R=golang-dev, bradfitz, remyoudompheng, r, dave CC=golang-dev https://golang.org/cl/6632046
2012-09-28strings: implement a faster single-string ReplacerEric Roshan-Eisner
The string searching is implemented separately so other functions may make use of it in the future. benchmark old ns/op new ns/op delta BenchmarkSingleMaxSkipping 125889 2474 -98.03% BenchmarkSingleLongSuffixFail 16252 1996 -87.72% BenchmarkSingleMatch 260793 136266 -47.75% benchmark old MB/s new MB/s speedup BenchmarkSingleMaxSkipping 79.43 4041.57 50.88x BenchmarkSingleLongSuffixFail 61.65 501.81 8.14x BenchmarkSingleMatch 57.52 110.08 1.91x R=nigeltao CC=golang-dev https://golang.org/cl/6545049
2012-09-18bytes, strings: add Fields benchmarksRuss Cox
The performance changes will be a few different CLs. Start with benchmarks as a baseline. R=golang-dev, r CC=golang-dev https://golang.org/cl/6537043
2012-09-17strings: implement a faster generic ReplacerEric Eisner
This also fixes the semantics of some corner cases with the empty match. TODOs for genericReplacer in the tests are fixed. benchmark old ns/op new ns/op delta BenchmarkGenericNoMatch 71395 3132 -95.61% BenchmarkGenericMatch1 75610 20280 -73.18% BenchmarkGenericMatch2 837995 86725 -89.65% R=nigeltao, rsc CC=golang-dev https://golang.org/cl/6492076
2012-09-12strings: fix NewReplacer(old0, new0, old1, new1, ...) to be consistentNigel Tao
when oldi == oldj. Benchmark numbers show no substantial change. R=eric.d.eisner, rogpeppe CC=golang-dev https://golang.org/cl/6496104
2012-09-11strings: more thorough Replacer tests.Nigel Tao
This verifies existing behavior. Some replacements are arguably wrong (these are marked with TODO) but changing behavior is left for a follow-up CL. Also fix that BenchmarkGenericMatch wasn't actually matching anything. R=rsc, eric.d.eisner CC=bradfitz, golang-dev https://golang.org/cl/6488110
2012-05-22go/parser: fix comment grouping (day 1 bug)Robert Griesemer
Comment groups must end at the end of a line (or the next non-comment token) if the group started on a line with non-comment tokens. This is important for correct computation of "lead" and "line" comments (Doc and Comment fields in AST nodes). Without this fix, the "line" comment for F1 in the following example: type T struct { F1 int // comment1 // comment2 F2 int } is "// comment1// comment2" rather than just "// comment1". This bug was present from Day 1 but only visible when looking at export-filtered ASTs where only comments associated with AST nodes are printed, and only in rare cases (e.g, in the case above, if F2 where not exported, godoc would show "// comment2" anyway because it was considered part of the "line" comment for F1). The bug fix is very small (parser.go). The bulk of the changes are additional test cases (parser_test.go). The fix exposed a caching bug in go/printer via one of the existing tests, hence the changes to printer.go. As an aside, the fix removes the the need for empty lines before an "// Output" comment for some special cases of code examples (e.g.: src/pkg/strings/example_test.go, Count example). No impact on gofmt formatting of src, misc. Fixes #3139. R=rsc CC=golang-dev https://golang.org/cl/6209080