Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(436)

Issue 12486043: code review 12486043: all: use strings.IndexByte instead of Index where possible (Closed)

Can't Edit
Can't Publish+Mail
Start Review
Created:
11 years, 7 months ago by bradfitz
Modified:
11 years, 7 months ago
Reviewers:
r, dave, khr, rsc
CC:
golang-dev, khr
Visibility:
Public.

Description

all: use strings.IndexByte instead of Index where possible

Patch Set 1 #

Patch Set 2 : diff -r 816f25454af2 https://go.googlecode.com/hg/ #

Patch Set 3 : diff -r 816f25454af2 https://go.googlecode.com/hg/ #

Patch Set 4 : diff -r b2b6f8df031e https://go.googlecode.com/hg/ #

Unified diffs Side-by-side diffs Delta from patch set Stats (+36 lines, -36 lines) Patch
M src/pkg/crypto/x509/pem_decrypt.go View 1 1 chunk +1 line, -1 line 0 comments Download
M src/pkg/debug/gosym/symtab.go View 1 2 chunks +2 lines, -2 lines 0 comments Download
M src/pkg/encoding/json/tags.go View 1 2 chunks +2 lines, -2 lines 0 comments Download
M src/pkg/encoding/xml/typeinfo.go View 1 1 chunk +1 line, -1 line 0 comments Download
M src/pkg/encoding/xml/xml.go View 1 1 chunk +1 line, -1 line 0 comments Download
M src/pkg/go/build/build.go View 1 3 chunks +3 lines, -3 lines 0 comments Download
M src/pkg/go/printer/printer.go View 1 1 chunk +1 line, -1 line 0 comments Download
M src/pkg/math/big/rat.go View 1 2 chunks +2 lines, -2 lines 0 comments Download
M src/pkg/mime/mediatype.go View 1 3 chunks +3 lines, -3 lines 0 comments Download
M src/pkg/net/http/cgi/child.go View 1 1 chunk +1 line, -1 line 0 comments Download
M src/pkg/net/http/cookie.go View 1 3 chunks +3 lines, -3 lines 0 comments Download
M src/pkg/net/http/fs.go View 1 1 chunk +1 line, -1 line 0 comments Download
M src/pkg/net/http/request.go View 1 2 chunks +3 lines, -3 lines 0 comments Download
M src/pkg/net/http/server.go View 1 2 chunks +2 lines, -2 lines 0 comments Download
M src/pkg/net/url/url.go View 1 2 chunks +2 lines, -2 lines 0 comments Download
M src/pkg/os/os_test.go View 1 1 chunk +1 line, -1 line 0 comments Download
M src/pkg/os/user/lookup_unix.go View 1 1 chunk +1 line, -1 line 0 comments Download
M src/pkg/path/match.go View 1 1 chunk +1 line, -1 line 0 comments Download
M src/pkg/regexp/exec_test.go View 1 2 chunks +2 lines, -2 lines 0 comments Download
M src/pkg/regexp/regexp.go View 1 2 chunks +2 lines, -2 lines 0 comments Download
M src/pkg/unicode/maketables.go View 1 1 chunk +1 line, -1 line 0 comments Download

Messages

Total messages: 10
bradfitz
Hello golang-dev@googlegroups.com, I'd like you to review this change to https://go.googlecode.com/hg/
11 years, 7 months ago (2013-08-05 22:37:42 UTC) #1
khr
On 2013/08/05 22:37:42, bradfitz wrote: > Hello mailto:golang-dev@googlegroups.com, > > I'd like you to review ...
11 years, 7 months ago (2013-08-05 22:43:29 UTC) #2
bradfitz
*** Submitted as https://code.google.com/p/go/source/detail?r=ab644299d124 *** all: use strings.IndexByte instead of Index where possible R=golang-dev, khr ...
11 years, 7 months ago (2013-08-05 22:46:09 UTC) #3
dave_cheney.net
Is there a vet rule for this, or did you just hit it with the ...
11 years, 7 months ago (2013-08-05 22:48:21 UTC) #4
bradfitz
grep -r -E -l 'strings.Index.*"."' pkg | grep go$ | xargs perl -pi -e "s:strings.Index\((.+), ...
11 years, 7 months ago (2013-08-05 22:50:27 UTC) #5
dave_cheney.net
Do you think it is worthy of a vet check, or go fix -s? On ...
11 years, 7 months ago (2013-08-05 22:55:06 UTC) #6
r
No. On Tue, Aug 6, 2013 at 8:54 AM, Dave Cheney <dave@cheney.net> wrote: > Do ...
11 years, 7 months ago (2013-08-05 22:57:41 UTC) #7
rsc
not lgtm This is exactly why strings.IndexByte didn't exist. This code is uglier and not ...
11 years, 7 months ago (2013-08-05 22:57:46 UTC) #8
bradfitz
I still like strings.IndexByte for consistency, regardless of this CL. If we're going to have ...
11 years, 7 months ago (2013-08-05 23:01:53 UTC) #9
rsc
11 years, 7 months ago (2013-08-05 23:05:51 UTC) #10
On Mon, Aug 5, 2013 at 7:01 PM, Brad Fitzpatrick <bradfitz@golang.org>wrote:

> I still like strings.IndexByte for consistency, regardless of this CL.  If
> we're going to have strings and bytes, the packages should feel the same.
>

OK.


> I agree this is longer, so could be considered uglier.  We can revert it.
>
> I disagree about "not faster".  I agree that it's not much faster, but
> this does avoid a function call.
>

That is true, but it is roughly the same. If you are calling Index or
IndexByte enough times that that function call adds up, there is something
bigger wrong with your program.

I was neutral on this CL, until I remembered when I first started adding
> APIs to the standard library, I was told to update the tree to use new APIs
> when I added them.
>

In general that is true. However, during the review you said the motivation
was for non-constant arguments. Feel free to use it to replace non-constant
single-byte string arguments, but please revert the uses with constants.

Thanks.
Russ
Sign in to reply to this message.

Powered by Google App Engine
RSS Feeds Recent Issues | This issue
This is Rietveld f62528b