Donovan Hide
937f91e1da
strings: faster Count, Index
...
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-19 10:36:15 -05:00
Rémy Oudompheng
23093f86ee
strings: better mean complexity for Count and Index.
...
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-17 13:07:17 +01:00
Brad Fitzpatrick
e515d80d5d
bytes, strings: add TrimPrefix and TrimSuffix
...
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
2013-02-01 08:41:25 -08:00
Robert Griesemer
465b9c35e5
gofmt: apply gofmt -w src misc
...
Remove trailing whitespace in comments.
No other changes.
R=r
CC=golang-dev
https://golang.org/cl/6815053
2012-10-30 13:38:01 -07:00
Russ Cox
0e60019a42
bytes, strings: add Fields benchmarks
...
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-18 15:02:08 -04:00
Rob Pike
6b772462e4
panics: use the new facilities of testing.B instead
...
Lots of panics go away.
Also fix a name error in html/template.
R=golang-dev, rsc
CC=golang-dev
https://golang.org/cl/5498045
2011-12-20 10:36:25 -08:00
Russ Cox
a250f37cbc
update tree for new default type rule
...
R=golang-dev, bradfitz
CC=golang-dev
https://golang.org/cl/5448091
2011-12-08 22:08:03 -05:00
Christopher Wedgwood
356b8ee26f
strings: fix test output
...
R=rsc, gri
CC=golang-dev
https://golang.org/cl/5445044
2011-11-28 09:51:03 -08:00
Scott Lawrence
0f0c25dccc
strings: Add ContainsAny and ContainsRune to correspond to IndexAny etc.
...
R=golang-dev, r
CC=golang-dev
https://golang.org/cl/5430046
2011-11-23 20:20:14 -08:00
Russ Cox
558e7fc332
various: avoid func compare
...
R=gri, r, bradfitz
CC=golang-dev
https://golang.org/cl/5371074
2011-11-13 22:57:19 -05:00
Rob Pike
45e3bcb343
renaming_3: gofix -r go1pkgrename src/pkg/[m-z]*
...
R=rsc
CC=golang-dev
https://golang.org/cl/5345045
2011-11-08 15:41:54 -08:00
Russ Cox
eb6929299b
src/pkg/[n-z]*: gofix -r error -force=error
...
R=golang-dev, bsiegert, iant
CC=golang-dev
https://golang.org/cl/5294074
2011-11-01 22:05:34 -04:00
Russ Cox
8f5718176f
bytes, strings: use rune
...
Various rune-based APIs change.
R=golang-dev, r
CC=golang-dev
https://golang.org/cl/5306044
2011-10-25 22:22:09 -07:00
Russ Cox
a8a18f6566
strings: add EqualFold
...
Case-insensitive strcmp without using ToLower.
(Using ToLower is not always correct, and it allocates.)
R=golang-dev, r
CC=golang-dev
https://golang.org/cl/5143044
2011-09-26 18:32:51 -04:00
Robert Griesemer
90564a9256
go/printer: changed max. number of newlines from 3 to 2
...
manual changes in src/pkg/go/printer, src/cmd/gofix/signal_test.go
(cd src/cmd/gofix/testdata; gofmt -w *.in *.out)
(cd src/pkg/go/printer; gotest -update)
gofmt -w misc src
runs all tests
R=golang-dev, rsc
CC=golang-dev
https://golang.org/cl/4715041
2011-07-14 14:39:40 -07:00
Rob Pike
ebb1566a46
strings.Split: make the default to split all.
...
Change the signature of Split to have no count,
assuming a full split, and rename the existing
Split with a count to SplitN.
Do the same to package bytes.
Add a gofix module.
R=adg, dsymonds, alex.brainman, rsc
CC=golang-dev
https://golang.org/cl/4661051
2011-06-28 09:43:14 +10:00
Robert Griesemer
9cd3372f9b
strings: implement UnreadByte, UnreadRune
...
Added corresponding tests.
R=rsc
CC=golang-dev
https://golang.org/cl/4560045
2011-05-26 11:02:07 -07:00
Brad Fitzpatrick
a7a854b82f
strings: Map: avoid allocation when string is unchanged
...
This speeds up strings.ToLower, etc.
before/after:
strings_test.BenchmarkMapNoChanges 1000000 1013 ns/op
strings_test.BenchmarkMapNoChanges 5000000 442 ns/op
R=r, rog, eh, rsc
CC=golang-dev
https://golang.org/cl/4306056
2011-03-28 09:41:57 -07:00
Rob Pike
f0cf7d296c
testing: shorten some tests.
...
These are the top runners. More to come.
Also print two digits of timing info under -test.v.
R=rsc
CC=golang-dev
https://golang.org/cl/4317044
2011-03-25 16:31:10 -07:00
Brad Fitzpatrick
64f75f1034
strings: better benchmark names; add BenchmarkIndex
...
R=dsymonds
CC=golang-dev
https://golang.org/cl/4264052
2011-03-08 09:58:18 -08:00
Brad Fitzpatrick
145108ed36
strings: add IndexRune tests, ASCII fast path
...
$ gotest -test.v -test.run=IndexRune -test.bench=.*
=== RUN strings_test.TestIndexRune
--- PASS: strings_test.TestIndexRune (0.0 seconds)
PASS
strings_test.BenchmarkIndexRune 20000000 105 ns/op
strings_test.BenchmarkIndexByte 50000000 48 ns/op
R=rsc, dsymonds
CC=golang-dev
https://golang.org/cl/4267050
2011-03-08 09:41:12 -08:00
Benny Siegert
8530e8ef65
strings: add LastIndexAny
...
The need for a LastIndexAny function has come up in the discussion
for https://golang.org/cl/3008041/ . This function is
implemented analogously to lastIndexFunc, using functions from
the utf8 package.
R=r, rsc, PeterGo
CC=golang-dev
https://golang.org/cl/3057041
2010-11-12 12:47:50 -08:00
Brad Fitzpatrick
e198a5086a
strings: Contains
...
Tiny helper to avoid strings.Index(s, sub) != -1
R=rsc, r2, r
CC=golang-dev
https://golang.org/cl/2265044
2010-11-01 14:32:48 -07:00
Robert Griesemer
3478891d12
gofmt -s -w src misc
...
R=r, rsc
CC=golang-dev
https://golang.org/cl/2662041
2010-10-22 10:06:33 -07:00
Roger Peppe
8ee986570a
strings: fix minor bug in LastIndexFunc
...
R=r, rsc
CC=golang-dev
https://golang.org/cl/2250042
2010-09-21 22:58:09 -04:00
Scott Lawrence
0cd8777255
strings: fix Split("", "", -1)
...
Fixes #980 .
Made it return an empty array, rather than crash.
Added relevant test cases to strings.
R=golang-dev, r
CC=golang-dev
https://golang.org/cl/1914041
2010-08-03 13:35:14 +10:00
Fazlul Shahriar
e356f1d88f
bytes: port IndexFunc and LastIndexFunc from strings package
...
This CL basically applies the same changes as
http://code.google.com/p/go/source/detail?r=5e0a29014e8e
but for bytes package.
R=r, rog
CC=golang-dev
https://golang.org/cl/1670052
2010-07-23 12:34:35 -07:00
Rob Pike
8684a08989
strings: add Title
...
strings.ToTitle converts all characters to title case, which for consistency with the
other To* functions it should continue to do. This CL adds string.Title, which
does a proper title-casing of the string.
A similar function for package bytes will follow once this is settled.
Fixes #933 .
R=rsc
CC=golang-dev
https://golang.org/cl/1869042
2010-07-20 00:03:59 -07:00
Rob Pike
38f1231f3e
strings and bytes.Split: make count of 0 mean 0, not infinite.
...
Use a count of -1 for infinity. Ditto for Replace.
R=rsc
CC=golang-dev
https://golang.org/cl/1704044
2010-07-01 14:08:14 -07:00
Russ Cox
0bf413ab8e
bytes, strings: add Replace
...
This is the Replace I suggested in the review of CL 1114041.
It's true that we already have
regexp.MustCompile(regexp.QuoteMeta(old)).ReplaceAll(s, new)
but because this Replace is doing a simpler job it is
simpler to call and inherently more efficient.
I will add the bytes implementation and tests to the
CL after the strings one has been reviewed.
R=r, cw
CC=golang-dev
https://golang.org/cl/1731048
2010-06-30 18:03:09 -07:00
Roger Peppe
18274e0075
Add IndexFunc and LastIndexFunc.
...
Change TrimRight and TrimLeft to use these functions.
Incidentally fix minor bug in TrimRight.
Add some test cases for this.
YMMV whether it's worth saving the closure allocation.
R=r, r2
CC=golang-dev, hoisie, rsc
https://golang.org/cl/1198044
2010-06-14 14:54:48 -07:00
Kyle Consalus
d7b4851586
strings: add ReadRune to Reader
...
R=rsc
CC=golang-dev
https://golang.org/cl/940041
2010-04-20 22:18:26 -07:00
Kyle Consalus
ad2c5a4984
Added strings.FieldsFunc, a generalization of strings.Fields in style of the strings.Trim*Func functions.
...
R=golang-dev, r
CC=golang-dev
https://golang.org/cl/824051
2010-04-19 16:36:50 -07:00
Michael Hoisie
92ac0cfbb2
strings: add IndexRune, Trim, TrimLeft, TrimRight, and the generic equivalents TrimFunc, TrimLeftFunc, TrimRightFunc
...
R=rsc, r
CC=golang-dev
https://golang.org/cl/799048
2010-04-09 18:57:03 -07:00
Rob Pike
4e2b7f8f41
Unicode: provide an ability to supplement the case-mapping tables
...
in character and string case mapping routines.
Add a custom mapper for Turkish and Azeri.
A more general solution for deriving the case information from Unicode's
SpecialCasing.txt will require more work.
Fixes #703 .
R=rsc, rsc1
CC=golang-dev, mdakin
https://golang.org/cl/824043
2010-03-30 17:51:03 -07:00
Robert Griesemer
d0ffee8abf
bytes, strings: IndexOfAny
...
+ first use in go/doc
R=r
CC=golang-dev
https://golang.org/cl/781041
2010-03-26 13:05:04 -07:00
Russ Cox
9750adbbad
strings: delete Runes, Bytes
...
gofmt -w -r 'strings.Bytes(a) -> []byte(a)' src/cmd src/pkg test/bench
gofmt -w -r 'strings.Runes(a) -> []int(a)' src/cmd src/pkg test/bench
delete unused imports
R=r
CC=golang-dev
https://golang.org/cl/224062
2010-02-25 16:01:29 -08:00
Andrey Mirtchovski
7f501c06f7
bytes, strings: add new function Fields
...
R=rsc, r, phf
CC=golang-dev
https://golang.org/cl/170046
2009-12-15 21:09:55 -08:00
Robert Griesemer
d65a5cce89
1) Change default gofmt default settings for
...
parsing and printing to new syntax.
Use -oldparser to parse the old syntax,
use -oldprinter to print the old syntax.
2) Change default gofmt formatting settings
to use tabs for indentation only and to use
spaces for alignment. This will make the code
alignment insensitive to an editor's tabwidth.
Use -spaces=false to use tabs for alignment.
3) Manually changed src/exp/parser/parser_test.go
so that it doesn't try to parse the parser's
source files using the old syntax (they have
new syntax now).
4) gofmt -w src misc test/bench
4th set of files.
R=rsc
CC=golang-dev
https://golang.org/cl/180049
2009-12-15 15:40:16 -08:00
Kei Son
128974adfd
bytes, strings: allow -1 in Map to mean "drop this character".
...
xml: drop invalid characters in attribute names
when constructing struct field names.
R=rsc
CC=r
https://golang.org/cl/157104
2009-12-11 10:37:48 -08:00
Peter Froehlich
1eba218e44
Runes: turn string into []int
...
Split: fixed typo in documentation
R=rsc, r, r1
https://golang.org/cl/157170
2009-12-02 20:47:38 -08:00
Rob Pike
8c1a627e5c
add bytes.IndexByte; common case we can make fast later.
...
also pick off the special case in strings.Index. don't want strings.IndexByte
because the call site will very rarely need to allocate and we can handle the
test in the code itself. bytes.IndexByte can avoid a common allocation.
R=rsc
CC=golang-dev
https://golang.org/cl/156091
2009-11-18 19:23:08 -08:00
David G. Andersen
37f71e8ad6
An asked-for-in #go-nuts extension to quickly create a repeated
...
copy of a string or a byte array.
strings.Repeat("-", 50)
bytes.Repeat(b, 99)
R=rsc
https://golang.org/cl/155063
2009-11-16 12:40:01 -08:00
Rob Pike
27779dd6cb
fix bug in bytes.Map and add test cases for Map in both strings and bytes packages.
...
thanks to ulrik.sverdrup for the test case.
Fixes #191 .
R=rsc
CC=golang-dev
https://golang.org/cl/155056
2009-11-15 12:07:27 -08:00
Robert Griesemer
3bb0032cd6
- replaced gofmt expression formatting algorithm with
...
rsc's algorithm
- applied gofmt -w misc src
- partial CL (last chunk)
R=rsc, r
http://go/go-review/1024041
2009-11-09 21:23:52 -08:00
Robert Griesemer
40621d5c0d
remove semis after statements in one-statement statement lists
...
R=rsc, r
http://go/go-review/1025029
2009-11-09 12:07:39 -08:00
Robert Griesemer
368f8cbc75
- fine-tuning of one-line func heuristic (nodes.go)
...
- enabled for function declarations (not just function literals)
- applied gofmt -w $GOROOT/src
(look for instance at src/pkg/debug/elf/elf.go)
R=r, rsc
CC=go-dev
http://go/go-review/1026006
2009-11-06 14:24:38 -08:00
Robert Griesemer
b8d88a9913
gofmt-ify strings, template
...
R=r
http://go/go-review/1018064
2009-11-05 15:12:37 -08:00
Russ Cox
5d436b9def
bytes.SplitAfter and strings.SplitAfter
...
most common usage is:
lines := strings.SplitAfter(text, "\n", 0)
R=r
http://go/go-review/1018042
2009-11-04 15:19:30 -08:00
Russ Cox
91549438d8
apply gofmt to rand reflect regexp rpc runtime sort strconv strings sync syscall testing time unicode unsafe utf8
...
R=gri
DELTA=1409 (79 added, 24 deleted, 1306 changed)
OCL=35415
CL=35437
2009-10-07 11:55:06 -07:00