Skip to content

codebase cleanup #238

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

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion dns/dnsmessage/message.go
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ const hexDigits = "0123456789abcdef"

func printString(str []byte) string {
buf := make([]byte, 0, len(str))
for i := 0; i < len(str); i++ {
for i := range len(str) {
c := str[i]
if c == '.' || c == '-' || c == ' ' ||
'A' <= c && c <= 'Z' ||
Expand Down
6 changes: 3 additions & 3 deletions dns/dnsmessage/message_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1279,7 +1279,7 @@ func BenchmarkParsing(b *testing.B) {
}

b.ReportAllocs()
for i := 0; i < b.N; i++ {
for range b.N {
benchmarkParsing(b, buf)
}
}
Expand Down Expand Up @@ -1422,7 +1422,7 @@ func BenchmarkPack(b *testing.B) {

b.ReportAllocs()

for i := 0; i < b.N; i++ {
for range b.N {
if _, err := msg.Pack(); err != nil {
b.Fatal("Message.Pack() =", err)
}
Expand All @@ -1435,7 +1435,7 @@ func BenchmarkAppendPack(b *testing.B) {

b.ReportAllocs()

for i := 0; i < b.N; i++ {
for range b.N {
if _, err := msg.AppendPack(buf[:0]); err != nil {
b.Fatal("Message.AppendPack() = ", err)
}
Expand Down
8 changes: 4 additions & 4 deletions http/httpguts/httplex.go
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ func ValidHeaderFieldName(v string) bool {
if len(v) == 0 {
return false
}
for i := 0; i < len(v); i++ {
for i := range len(v) {
if !isTokenTable[v[i]] {
return false
}
Expand All @@ -218,7 +218,7 @@ func ValidHostHeader(h string) bool {
// But we're going to be much more lenient for now and just
// search for any byte that's not a valid byte in any of those
// expressions.
for i := 0; i < len(h); i++ {
for i := range len(h) {
if !validHostByte[h[i]] {
return false
}
Expand Down Expand Up @@ -301,7 +301,7 @@ var validHostByte = [256]bool{
// This function does not (yet?) properly handle the rejection of
// strings that begin or end with SP or HTAB.
func ValidHeaderFieldValue(v string) bool {
for i := 0; i < len(v); i++ {
for i := range len(v) {
b := v[i]
if isCTL(b) && !isLWS(b) {
return false
Expand All @@ -311,7 +311,7 @@ func ValidHeaderFieldValue(v string) bool {
}

func isASCII(s string) bool {
for i := 0; i < len(s); i++ {
for i := range len(s) {
if s[i] >= utf8.RuneSelf {
return false
}
Expand Down
4 changes: 2 additions & 2 deletions http/httpguts/httplex_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ func TestIsTokenRune(t *testing.T) {
}

func BenchmarkIsTokenRune(b *testing.B) {
for i := 0; i < b.N; i++ {
for range b.N {
var r rune
for ; r < 1024; r++ {
IsTokenRune(r)
Expand Down Expand Up @@ -140,7 +140,7 @@ func BenchmarkValidHeaderFieldName(b *testing.B) {
}
b.ReportAllocs()
b.ResetTimer()
for i := 0; i < b.N; i++ {
for range b.N {
for _, name := range names {
ValidHeaderFieldName(name)
}
Expand Down
2 changes: 1 addition & 1 deletion http/httpproxy/proxy.go
Original file line number Diff line number Diff line change
Expand Up @@ -313,7 +313,7 @@ func idnaASCII(v string) (string, error) {
}

func isASCII(s string) bool {
for i := 0; i < len(s); i++ {
for i := range len(s) {
if s[i] >= utf8.RuneSelf {
return false
}
Expand Down
2 changes: 1 addition & 1 deletion http/httpproxy/proxy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -394,7 +394,7 @@ func BenchmarkProxyForURL(b *testing.B) {
}
proxyFunc := cfg.ProxyFunc()
b.Run(test.host, func(b *testing.B) {
for n := 0; n < b.N; n++ {
for range b.N {
if au, e := proxyFunc(u); e != nil && test.match == (au != nil) {
b.Errorf("useProxy(%v) = %v, want %v", test.host, !test.match, test.match)
}
Expand Down
4 changes: 2 additions & 2 deletions http2/ascii.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ func asciiEqualFold(s, t string) bool {
if len(s) != len(t) {
return false
}
for i := 0; i < len(s); i++ {
for i := range len(s) {
if lower(s[i]) != lower(t[i]) {
return false
}
Expand All @@ -35,7 +35,7 @@ func lower(b byte) byte {
// isASCIIPrint returns whether s is ASCII and printable according to
// https://tools.ietf.org/html/rfc20#section-4.2.
func isASCIIPrint(s string) bool {
for i := 0; i < len(s); i++ {
for i := range len(s) {
if s[i] < ' ' || s[i] > '~' {
return false
}
Expand Down
8 changes: 4 additions & 4 deletions http2/frame.go
Original file line number Diff line number Diff line change
Expand Up @@ -771,7 +771,7 @@ func (f *SettingsFrame) IsAck() bool {

func (f *SettingsFrame) Value(id SettingID) (v uint32, ok bool) {
f.checkValid()
for i := 0; i < f.NumSettings(); i++ {
for i := range f.NumSettings() {
if s := f.Setting(i); s.ID == id {
return s.Val, true
}
Expand Down Expand Up @@ -800,7 +800,7 @@ func (f *SettingsFrame) HasDuplicates() bool {
// If it's small enough (the common case), just do the n^2
// thing and avoid a map allocation.
if num < 10 {
for i := 0; i < num; i++ {
for i := range num {
idi := f.Setting(i).ID
for j := i + 1; j < num; j++ {
idj := f.Setting(j).ID
Expand All @@ -812,7 +812,7 @@ func (f *SettingsFrame) HasDuplicates() bool {
return false
}
seen := map[SettingID]bool{}
for i := 0; i < num; i++ {
for i := range num {
id := f.Setting(i).ID
if seen[id] {
return true
Expand All @@ -826,7 +826,7 @@ func (f *SettingsFrame) HasDuplicates() bool {
// It stops and returns the first error.
func (f *SettingsFrame) ForeachSetting(fn func(Setting) error) error {
f.checkValid()
for i := 0; i < f.NumSettings(); i++ {
for i := range f.NumSettings() {
if err := fn(f.Setting(i)); err != nil {
return err
}
Expand Down
10 changes: 5 additions & 5 deletions http2/frame_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -985,7 +985,7 @@ func TestMetaFrameHeader(t *testing.T) {
w: func(f *Framer) {
var he hpackEncoder
var pairs = []string{":method", "GET", ":path", "/"}
for i := 0; i < 100; i++ {
for range 100 {
pairs = append(pairs, "foo", "bar")
}
all := he.encodeHeaderRaw(t, pairs...)
Expand Down Expand Up @@ -1129,21 +1129,21 @@ func TestSetReuseFrames(t *testing.T) {
// SetReuseFrames only currently implements reuse of DataFrames.
firstDf := readAndVerifyDataFrame("ABC", 3, fr, buf, t)

for i := 0; i < 10; i++ {
for range 10 {
df := readAndVerifyDataFrame("XYZ", 3, fr, buf, t)
if df != firstDf {
t.Errorf("Expected Framer to return references to the same DataFrame. Have %v and %v", &df, &firstDf)
}
}

for i := 0; i < 10; i++ {
for range 10 {
df := readAndVerifyDataFrame("", 0, fr, buf, t)
if df != firstDf {
t.Errorf("Expected Framer to return references to the same DataFrame. Have %v and %v", &df, &firstDf)
}
}

for i := 0; i < 10; i++ {
for range 10 {
df := readAndVerifyDataFrame("HHH", 3, fr, buf, t)
if df != firstDf {
t.Errorf("Expected Framer to return references to the same DataFrame. Have %v and %v", &df, &firstDf)
Expand All @@ -1158,7 +1158,7 @@ func TestSetReuseFramesMoreThanOnce(t *testing.T) {
firstDf := readAndVerifyDataFrame("ABC", 3, fr, buf, t)
fr.SetReuseFrames()

for i := 0; i < 10; i++ {
for range 10 {
df := readAndVerifyDataFrame("XYZ", 3, fr, buf, t)
// SetReuseFrames should be idempotent
fr.SetReuseFrames()
Expand Down
2 changes: 1 addition & 1 deletion http2/gotrack.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ func parseUintBytes(s []byte, base int, bitSize int) (n uint64, err error) {
cutoff = cutoff64(base)
maxVal = 1<<uint(bitSize) - 1

for i := 0; i < len(s); i++ {
for i := range len(s) {
var v byte
d := s[i]
switch {
Expand Down
6 changes: 3 additions & 3 deletions http2/server_push_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ func TestServer_Push_Success(t *testing.T) {
// Send one request, which should push two responses.
st.greet()
getSlash(st)
for k := 0; k < 3; k++ {
for k := range 3 {
select {
case <-time.After(2 * time.Second):
t.Errorf("timeout waiting for handler %d to finish", k)
Expand Down Expand Up @@ -274,7 +274,7 @@ func TestServer_Push_SuccessNoRace(t *testing.T) {
// Send one request, which should push one response.
st.greet()
getSlash(st)
for k := 0; k < 2; k++ {
for k := range 2 {
select {
case <-time.After(2 * time.Second):
t.Errorf("timeout waiting for handler %d to finish", k)
Expand Down Expand Up @@ -542,7 +542,7 @@ func TestServer_Push_Underflow(t *testing.T) {
// Send several requests.
st.greet()
const numRequests = 4
for i := 0; i < numRequests; i++ {
for i := range numRequests {
st.writeHeaders(HeadersFrameParam{
StreamID: uint32(1 + i*2), // clients send odd numbers
BlockFragment: st.encodeHeader(),
Expand Down
36 changes: 18 additions & 18 deletions http2/server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -447,7 +447,7 @@ func (st *serverTester) greetAndCheckSettings(checkSetting func(s Setting) error
var gotSettingsAck bool
var gotWindowUpdate bool

for i := 0; i < 2; i++ {
for range 2 {
f := st.readFrame()
if f == nil {
st.t.Fatal("wanted a settings ACK and window update, got none")
Expand Down Expand Up @@ -1197,7 +1197,7 @@ func TestServer_MaxQueuedControlFrames(t *testing.T) {
// Send maxQueuedControlFrames pings, plus a few extra
// to account for ones that enter the server's write buffer.
const extraPings = 2
for i := 0; i < maxQueuedControlFrames+extraPings; i++ {
for range maxQueuedControlFrames + extraPings {
pingData := [8]byte{1, 2, 3, 4, 5, 6, 7, 8}
st.fr.WritePing(false, pingData)
}
Expand All @@ -1209,7 +1209,7 @@ func TestServer_MaxQueuedControlFrames(t *testing.T) {

st.advance(goAwayTimeout)
// Some frames may have persisted in the server's buffers.
for i := 0; i < 10; i++ {
for range 10 {
if st.readFrame() == nil {
break
}
Expand Down Expand Up @@ -1406,7 +1406,7 @@ func TestServer_RSTStream_Unblocks_Header_Write(t *testing.T) {
if testing.Short() {
n = 5
}
for i := 0; i < n; i++ {
for range n {
testServer_RSTStream_Unblocks_Header_Write(t)
}
}
Expand Down Expand Up @@ -2282,12 +2282,12 @@ func TestServer_Rejects_Too_Many_Streams(t *testing.T) {
EndHeaders: true,
})
}
for i := 0; i < defaultMaxStreams; i++ {
for range defaultMaxStreams {
sendReq(streamID())
<-inHandler
}
defer func() {
for i := 0; i < defaultMaxStreams; i++ {
for range defaultMaxStreams {
leaveHandler <- true
}
}()
Expand Down Expand Up @@ -2330,7 +2330,7 @@ func TestServer_Rejects_Too_Many_Streams(t *testing.T) {
func TestServer_Response_ManyHeaders_With_Continuation(t *testing.T) {
testServerResponse(t, func(w http.ResponseWriter, r *http.Request) error {
h := w.Header()
for i := 0; i < 5000; i++ {
for i := range 5000 {
h.Set(fmt.Sprintf("x-header-%d", i), fmt.Sprintf("x-value-%d", i))
}
return nil
Expand Down Expand Up @@ -2912,7 +2912,7 @@ func BenchmarkServerGets(b *testing.B) {
b.Fatal(err)
}

for i := 0; i < b.N; i++ {
for i := range b.N {
id := 1 + uint32(i)*2
st.writeHeaders(HeadersFrameParam{
StreamID: id,
Expand Down Expand Up @@ -2949,7 +2949,7 @@ func BenchmarkServerPosts(b *testing.B) {
b.Fatal(err)
}

for i := 0; i < b.N; i++ {
for i := range b.N {
id := 1 + uint32(i)*2
st.writeHeaders(HeadersFrameParam{
StreamID: id,
Expand Down Expand Up @@ -3295,7 +3295,7 @@ func BenchmarkServer_GetRequest(b *testing.B) {
b.Fatal(err)
}
hbf := st.encodeHeader(":method", "GET")
for i := 0; i < b.N; i++ {
for i := range b.N {
streamID := uint32(1 + 2*i)
st.writeHeaders(HeadersFrameParam{
StreamID: streamID,
Expand Down Expand Up @@ -3326,7 +3326,7 @@ func BenchmarkServer_PostRequest(b *testing.B) {
b.Fatal(err)
}
hbf := st.encodeHeader(":method", "POST")
for i := 0; i < b.N; i++ {
for i := range b.N {
streamID := uint32(1 + 2*i)
st.writeHeaders(HeadersFrameParam{
StreamID: streamID,
Expand Down Expand Up @@ -3598,7 +3598,7 @@ func TestUnreadFlowControlReturned_Server(t *testing.T) {
if testing.Short() {
iters = 20
}
for i := 0; i < iters; i++ {
for range iters {
body := io.MultiReader(
io.LimitReader(neverEnding('A'), 16<<10),
funcReader(func([]byte) (n int, err error) {
Expand Down Expand Up @@ -3703,7 +3703,7 @@ func TestServerIdleTimeout_AfterRequest(t *testing.T) {
// Verify that it doesn't race.
// See https://github.com/grpc/grpc-go/pull/938
func TestRequestBodyReadCloseRace(t *testing.T) {
for i := 0; i < 100; i++ {
for range 100 {
body := &requestBody{
pipe: &pipe{
b: new(bytes.Buffer),
Expand Down Expand Up @@ -3733,7 +3733,7 @@ func TestIssue20704Race(t *testing.T) {
)

ts := newTestServer(t, func(w http.ResponseWriter, r *http.Request) {
for i := 0; i < itemCount; i++ {
for range itemCount {
_, err := w.Write(make([]byte, itemSize))
if err != nil {
return
Expand All @@ -3745,7 +3745,7 @@ func TestIssue20704Race(t *testing.T) {
defer tr.CloseIdleConnections()
cl := &http.Client{Transport: tr}

for i := 0; i < 1000; i++ {
for range 1000 {
resp, err := cl.Get(ts.URL)
if err != nil {
t.Fatal(err)
Expand Down Expand Up @@ -4474,7 +4474,7 @@ func TestServerMaxHandlerGoroutines(t *testing.T) {
streamID += 2

// Start another two requests. Don't reset these.
for i := 0; i < 2; i++ {
for range 2 {
st.writeHeaders(HeadersFrameParam{
StreamID: streamID,
BlockFragment: st.encodeHeader(),
Expand Down Expand Up @@ -4537,7 +4537,7 @@ func TestServerContinuationFlood(t *testing.T) {
BlockFragment: st.encodeHeader(),
EndStream: true,
})
for i := 0; i < 1000; i++ {
for i := range 1000 {
st.fr.WriteContinuation(1, false, st.encodeHeaderRaw(
fmt.Sprintf("x-%v", i), "1234567890",
))
Expand Down Expand Up @@ -4697,7 +4697,7 @@ func TestServerWriteByteTimeout(t *testing.T) {
})

// Read a few bytes, staying just under WriteByteTimeout.
for i := 0; i < 10; i++ {
for i := range 10 {
st.advance(timeout - 1)
if n, err := st.cc.Read(make([]byte, 1)); n != 1 || err != nil {
t.Fatalf("read %v: %v, %v; want 1, nil", i, n, err)
Expand Down
Loading