Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

strings: Index(s, "x") not as optimized as bytes.IndexByte #3751

Closed
bradfitz opened this issue Jun 18, 2012 · 19 comments
Closed

strings: Index(s, "x") not as optimized as bytes.IndexByte #3751

bradfitz opened this issue Jun 18, 2012 · 19 comments

Comments

@bradfitz
Copy link
Contributor

bytes.IndexByte is implemented in assembly:

http://golang.org/pkg/bytes/#IndexByte

The strings package lacks an IndexByte method.  It does have a special case for Index
when len(sep) == 1, but not in assembly:

http://golang.org/src/pkg/strings/strings.go?s=1834:1863#L71

Low priority, but inconsistent. I noticed a couple weeks ago when I was looking at some
profiles.
@robpike
Copy link
Contributor

robpike commented Jun 18, 2012

Comment 1:

Status changed to Accepted.

@rsc
Copy link
Contributor

rsc commented Sep 12, 2012

Comment 2:

Labels changed: added go1.1.

@rsc
Copy link
Contributor

rsc commented Dec 10, 2012

Comment 3:

Labels changed: added size-l.

@bradfitz
Copy link
Contributor Author

Comment 4:

Also:
runtime.eqstring doesn't use the assembly from bytes/asm_amd64.s

@adg
Copy link
Contributor

adg commented Feb 13, 2013

Comment 5:

What's the best approach here? Copy the code from bytes, or use unsafe tricks to convert
the string to a []byte and defer to bytes.IndexByte?

@bradfitz
Copy link
Contributor Author

Comment 6:

Russ was proposing moving some of this shared code into package runtime, and having
bytes, strings, and the runtime use it.

@alberts
Copy link
Contributor

alberts commented Feb 13, 2013

Comment 7:

On the runtime.eqstring topic: I've been dealing with database type app that scans
through lots of strings doing equality comparisons, where depending on some details, the
variability in the string is known to be at the start or at the end.
I believe it would have been very useful to have something like
strings.Equal(s1, s2 string, reverse bool) bool
that calls into some suitable assembler somewhere.
Could probably roll our own, but this seems close to the kind of thing the runtime
should be good at.

@bradfitz
Copy link
Contributor Author

Comment 8:

That's a pretty gross API for the strings package, or the runtime package.

@rsc
Copy link
Contributor

rsc commented Feb 13, 2013

Comment 9:

Please do not send CLs for this issue. I will take care of it later.

@rsc
Copy link
Contributor

rsc commented Mar 12, 2013

Comment 10:

Labels changed: added go1.1maybe, removed go1.1.

@randall77
Copy link
Contributor

Comment 12:

This issue was updated by revision 3d5daa2.

R=bradfitz, r, khr, dave, remyoudompheng, fullung, minux.ma, ality
CC=golang-dev
https://golang.org/cl/8056043

@bradfitz
Copy link
Contributor Author

bradfitz commented Apr 3, 2013

Comment 13:

Labels changed: added optimization.

@bradfitz
Copy link
Contributor Author

bradfitz commented Apr 3, 2013

Comment 14:

Labels changed: added performance.

@bradfitz
Copy link
Contributor Author

bradfitz commented Apr 3, 2013

Comment 15:

Labels changed: removed optimization.

@bradfitz
Copy link
Contributor Author

Comment 16:

I opened a related issue #5354 for bytes.Compare.

@robpike
Copy link
Contributor

robpike commented May 18, 2013

Comment 17:

Labels changed: added go1.2maybe, removed go1.1maybe.

@rsc
Copy link
Contributor

rsc commented Jul 30, 2013

Comment 18:

Labels changed: added feature.

@bradfitz
Copy link
Contributor Author

bradfitz commented Aug 1, 2013

Comment 19:

This issue was updated by revision e2a1bd6.

R=golang-dev, r
CC=golang-dev
https://golang.org/cl/12289043

@bradfitz
Copy link
Contributor Author

bradfitz commented Aug 5, 2013

Comment 20:

This issue was closed by revision 598c789.

Status changed to Fixed.

@rsc rsc added this to the Go1.2 milestone Apr 14, 2015
@rsc rsc removed the go1.2maybe label Apr 14, 2015
@golang golang locked and limited conversation to collaborators Jun 24, 2016
This issue was closed.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

7 participants