[go] net: use internal/bytealg insetad of linkname tricks

100 views
Skip to first unread message

Ilya Tocar (Gerrit)

unread,
Aug 21, 2018, 4:10:39 PM8/21/18
to Ian Lance Taylor, goph...@pubsubhelper.golang.org, golang-co...@googlegroups.com

Ilya Tocar has uploaded this change for review.

View Change

net: use internal/bytealg insetad of linkname tricks

We are currently using go:linkname for some algorithms from
strings/bytes packages, to avoid importing strings/bytes.
But strings/bytes are just wrappers around internal/bytealg, so
we should use internal/bytealg directly.

Change-Id: I2836f779b88bf8876d5fa725043a6042bdda0390
---
M src/net/conf.go
M src/net/dnsconfig_unix.go
M src/net/hosts.go
M src/net/ip.go
M src/net/ipsock.go
M src/net/lookup_unix.go
M src/net/nss.go
M src/net/parse.go
M src/net/port_unix.go
M src/net/sockopt_posix.go
10 files changed, 39 insertions(+), 45 deletions(-)

diff --git a/src/net/conf.go b/src/net/conf.go
index 71ed136..127aba3 100644
--- a/src/net/conf.go
+++ b/src/net/conf.go
@@ -7,6 +7,7 @@
package net

import (
+ "internal/bytealg"
"os"
"runtime"
"sync"
@@ -132,7 +133,7 @@
if c.forceCgoLookupHost || c.resolv.unknownOpt || c.goos == "android" {
return fallbackOrder
}
- if byteIndex(hostname, '\\') != -1 || byteIndex(hostname, '%') != -1 {
+ if bytealg.IndexByteString(hostname, '\\') != -1 || bytealg.IndexByteString(hostname, '%') != -1 {
// Don't deal with special form hostnames with backslashes
// or '%'.
return fallbackOrder
@@ -301,7 +302,7 @@
dnsMode = s
}
}
- if i := byteIndex(goDebug, '+'); i != -1 {
+ if i := bytealg.IndexByteString(goDebug, '+'); i != -1 {
parsePart(goDebug[:i])
parsePart(goDebug[i+1:])
return
diff --git a/src/net/dnsconfig_unix.go b/src/net/dnsconfig_unix.go
index 707fd6f..64c66f9 100644
--- a/src/net/dnsconfig_unix.go
+++ b/src/net/dnsconfig_unix.go
@@ -9,6 +9,7 @@
package net

import (
+ "internal/bytealg"
"os"
"sync/atomic"
"time"
@@ -155,7 +156,7 @@
// best effort
return nil
}
- if i := byteIndex(hn, '.'); i >= 0 && i < len(hn)-1 {
+ if i := bytealg.IndexByteString(hn, '.'); i >= 0 && i < len(hn)-1 {
return []string{ensureRooted(hn[i+1:])}
}
return nil
diff --git a/src/net/hosts.go b/src/net/hosts.go
index ebc0353..5c560f3 100644
--- a/src/net/hosts.go
+++ b/src/net/hosts.go
@@ -5,6 +5,7 @@
package net

import (
+ "internal/bytealg"
"sync"
"time"
)
@@ -68,7 +69,7 @@
return
}
for line, ok := file.readLine(); ok; line, ok = file.readLine() {
- if i := byteIndex(line, '#'); i >= 0 {
+ if i := bytealg.IndexByteString(line, '#'); i >= 0 {
// Discard comments.
line = line[0:i]
}
diff --git a/src/net/ip.go b/src/net/ip.go
index 410de92..9a6fda0 100644
--- a/src/net/ip.go
+++ b/src/net/ip.go
@@ -12,7 +12,7 @@

package net

-import _ "unsafe" // for go:linkname
+import "internal/bytealg"

// IP address lengths (bytes).
const (
@@ -246,7 +246,7 @@
if len(mask) == IPv6len && len(ip) == IPv4len && allFF(mask[:12]) {
mask = mask[12:]
}
- if len(mask) == IPv4len && len(ip) == IPv6len && bytesEqual(ip[:12], v4InV6Prefix) {
+ if len(mask) == IPv4len && len(ip) == IPv6len && bytealg.Equal(ip[:12], v4InV6Prefix) {
ip = ip[12:]
}
n := len(ip)
@@ -406,21 +406,17 @@
// considered to be equal.
func (ip IP) Equal(x IP) bool {
if len(ip) == len(x) {
- return bytesEqual(ip, x)
+ return bytealg.Equal(ip, x)
}
if len(ip) == IPv4len && len(x) == IPv6len {
- return bytesEqual(x[0:12], v4InV6Prefix) && bytesEqual(ip, x[12:])
+ return bytealg.Equal(x[0:12], v4InV6Prefix) && bytealg.Equal(ip, x[12:])
}
if len(ip) == IPv6len && len(x) == IPv4len {
- return bytesEqual(ip[0:12], v4InV6Prefix) && bytesEqual(ip[12:], x)
+ return bytealg.Equal(ip[0:12], v4InV6Prefix) && bytealg.Equal(ip[12:], x)
}
return false
}

-// bytes.Equal is implemented in runtime/asm_$goarch.s
-//go:linkname bytesEqual bytes.Equal
-func bytesEqual(x, y []byte) bool
-
func (ip IP) matchAddrFamily(x IP) bool {
return ip.To4() != nil && x.To4() != nil || ip.To16() != nil && ip.To4() == nil && x.To16() != nil && x.To4() == nil
}
@@ -711,7 +707,7 @@
// For example, ParseCIDR("192.0.2.1/24") returns the IP address
// 192.0.2.1 and the network 192.0.2.0/24.
func ParseCIDR(s string) (IP, *IPNet, error) {
- i := byteIndex(s, '/')
+ i := bytealg.IndexByteString(s, '/')
if i < 0 {
return nil, nil, &ParseError{Type: "CIDR address", Text: s}
}
diff --git a/src/net/ipsock.go b/src/net/ipsock.go
index f4ff82b..84fa0ac 100644
--- a/src/net/ipsock.go
+++ b/src/net/ipsock.go
@@ -6,6 +6,7 @@

import (
"context"
+ "internal/bytealg"
"sync"
)

@@ -170,7 +171,7 @@

if hostport[0] == '[' {
// Expect the first ']' just before the last ':'.
- end := byteIndex(hostport, ']')
+ end := bytealg.IndexByteString(hostport, ']')
if end < 0 {
return addrErr(hostport, "missing ']' in address")
}
@@ -192,14 +193,14 @@
j, k = 1, end+1 // there can't be a '[' resp. ']' before these positions
} else {
host = hostport[:i]
- if byteIndex(host, ':') >= 0 {
+ if bytealg.IndexByteString(host, ':') >= 0 {
return addrErr(hostport, tooManyColons)
}
}
- if byteIndex(hostport[j:], '[') >= 0 {
+ if bytealg.IndexByteString(hostport[j:], '[') >= 0 {
return addrErr(hostport, "unexpected '[' in address")
}
- if byteIndex(hostport[k:], ']') >= 0 {
+ if bytealg.IndexByteString(hostport[k:], ']') >= 0 {
return addrErr(hostport, "unexpected ']' in address")
}

@@ -226,7 +227,7 @@
func JoinHostPort(host, port string) string {
// We assume that host is a literal IPv6 address if host has
// colons.
- if byteIndex(host, ':') >= 0 {
+ if bytealg.IndexByteString(host, ':') >= 0 {
return "[" + host + "]:" + port
}
return host + ":" + port
diff --git a/src/net/lookup_unix.go b/src/net/lookup_unix.go
index 2c3191a..04f443b 100644
--- a/src/net/lookup_unix.go
+++ b/src/net/lookup_unix.go
@@ -8,6 +8,7 @@

import (
"context"
+ "internal/bytealg"
"sync"
"syscall"

@@ -27,7 +28,7 @@

for line, ok := file.readLine(); ok; line, ok = file.readLine() {
// tcp 6 TCP # transmission control protocol
- if i := byteIndex(line, '#'); i >= 0 {
+ if i := bytealg.IndexByteString(line, '#'); i >= 0 {
line = line[0:i]
}
f := getFields(line)
diff --git a/src/net/nss.go b/src/net/nss.go
index 08c3e6a..f10bb52 100644
--- a/src/net/nss.go
+++ b/src/net/nss.go
@@ -8,6 +8,7 @@

import (
"errors"
+ "internal/bytealg"
"io"
"os"
)
@@ -85,7 +86,7 @@
if len(line) == 0 {
return nil
}
- colon := bytesIndexByte(line, ':')
+ colon := bytealg.IndexByte(line, ':')
if colon == -1 {
return errors.New("no colon on line")
}
@@ -96,7 +97,7 @@
if len(srcs) == 0 {
break
}
- sp := bytesIndexByte(srcs, ' ')
+ sp := bytealg.IndexByte(srcs, ' ')
var src string
if sp == -1 {
src = string(srcs)
@@ -108,7 +109,7 @@
var criteria []nssCriterion
// See if there's a criteria block in brackets.
if len(srcs) > 0 && srcs[0] == '[' {
- bclose := bytesIndexByte(srcs, ']')
+ bclose := bytealg.IndexByte(srcs, ']')
if bclose == -1 {
return errors.New("unclosed criterion bracket")
}
@@ -143,7 +144,7 @@
if len(f) < 3 {
return errors.New("criterion too short")
}
- eq := bytesIndexByte(f, '=')
+ eq := bytealg.IndexByte(f, '=')
if eq == -1 {
return errors.New("criterion lacks equal sign")
}
diff --git a/src/net/parse.go b/src/net/parse.go
index e356cb1..cdb35bb 100644
--- a/src/net/parse.go
+++ b/src/net/parse.go
@@ -8,10 +8,10 @@
package net

import (
+ "internal/bytealg"
"io"
"os"
"time"
- _ "unsafe" // For go:linkname
)

type file struct {
@@ -80,17 +80,11 @@
return st.ModTime(), st.Size(), nil
}

-// byteIndex is strings.IndexByte. It returns the index of the
-// first instance of c in s, or -1 if c is not present in s.
-// strings.IndexByte is implemented in runtime/asm_$GOARCH.s
-//go:linkname byteIndex strings.IndexByte
-func byteIndex(s string, c byte) int
-
// Count occurrences in s of any bytes in t.
func countAnyByte(s string, t string) int {
n := 0
for i := 0; i < len(s); i++ {
- if byteIndex(t, s[i]) >= 0 {
+ if bytealg.IndexByteString(t, s[i]) >= 0 {
n++
}
}
@@ -103,7 +97,7 @@
n := 0
last := 0
for i := 0; i < len(s); i++ {
- if byteIndex(t, s[i]) >= 0 {
+ if bytealg.IndexByteString(t, s[i]) >= 0 {
if last < i {
a[n] = s[last:i]
n++
@@ -276,7 +270,7 @@
// removeComment returns line, removing any '#' byte and any following
// bytes.
func removeComment(line []byte) []byte {
- if i := bytesIndexByte(line, '#'); i != -1 {
+ if i := bytealg.IndexByte(line, '#'); i != -1 {
return line[:i]
}
return line
@@ -287,7 +281,7 @@
// It returns the first non-nil error returned by fn.
func foreachLine(x []byte, fn func(line []byte) error) error {
for len(x) > 0 {
- nl := bytesIndexByte(x, '\n')
+ nl := bytealg.IndexByte(x, '\n')
if nl == -1 {
return fn(x)
}
@@ -305,7 +299,7 @@
func foreachField(x []byte, fn func(field []byte) error) error {
x = trimSpace(x)
for len(x) > 0 {
- sp := bytesIndexByte(x, ' ')
+ sp := bytealg.IndexByte(x, ' ')
if sp == -1 {
return fn(x)
}
@@ -319,12 +313,6 @@
return nil
}

-// bytesIndexByte is bytes.IndexByte. It returns the index of the
-// first instance of c in s, or -1 if c is not present in s.
-// bytes.IndexByte is implemented in runtime/asm_$GOARCH.s
-//go:linkname bytesIndexByte bytes.IndexByte
-func bytesIndexByte(s []byte, c byte) int
-
// stringsHasSuffix is strings.HasSuffix. It reports whether s ends in
// suffix.
func stringsHasSuffix(s, suffix string) bool {
diff --git a/src/net/port_unix.go b/src/net/port_unix.go
index 64c7f57..d0882a2 100644
--- a/src/net/port_unix.go
+++ b/src/net/port_unix.go
@@ -8,7 +8,10 @@

package net

-import "sync"
+import (
+ "internal/bytealg"
+ "sync"
+)

var onceReadServices sync.Once

@@ -21,7 +24,7 @@

for line, ok := file.readLine(); ok; line, ok = file.readLine() {
// "http 80/tcp www www-http # World Wide Web HTTP"
- if i := byteIndex(line, '#'); i >= 0 {
+ if i := bytealg.IndexByteString(line, '#'); i >= 0 {
line = line[:i]
}
f := getFields(line)
diff --git a/src/net/sockopt_posix.go b/src/net/sockopt_posix.go
index e8af84f..83ab012 100644
--- a/src/net/sockopt_posix.go
+++ b/src/net/sockopt_posix.go
@@ -7,6 +7,7 @@
package net

import (
+ "internal/bytealg"
"runtime"
"syscall"
)
@@ -94,7 +95,7 @@
}
}
done:
- if bytesEqual(mreq.Multiaddr[:], IPv4zero.To4()) {
+ if bytealg.Equal(mreq.Multiaddr[:], IPv4zero.To4()) {
return errNoSuchMulticastInterface
}
return nil

To view, visit change 130515. To unsubscribe, or for help writing mail filters, visit settings.

Gerrit-Project: go
Gerrit-Branch: master
Gerrit-Change-Id: I2836f779b88bf8876d5fa725043a6042bdda0390
Gerrit-Change-Number: 130515
Gerrit-PatchSet: 1
Gerrit-Owner: Ilya Tocar <ilya....@intel.com>
Gerrit-Reviewer: Ilya Tocar <ilya....@intel.com>
Gerrit-MessageType: newchange

Gobot Gobot (Gerrit)

unread,
Aug 21, 2018, 4:10:52 PM8/21/18
to Ilya Tocar, goph...@pubsubhelper.golang.org, golang-co...@googlegroups.com

TryBots beginning. Status page: https://farmer.golang.org/try?commit=798d6eb8

View Change

    To view, visit change 130515. To unsubscribe, or for help writing mail filters, visit settings.

    Gerrit-Project: go
    Gerrit-Branch: master
    Gerrit-Change-Id: I2836f779b88bf8876d5fa725043a6042bdda0390
    Gerrit-Change-Number: 130515
    Gerrit-PatchSet: 1
    Gerrit-Owner: Ilya Tocar <ilya....@intel.com>
    Gerrit-Reviewer: Ilya Tocar <ilya....@intel.com>
    Gerrit-CC: Gobot Gobot <go...@golang.org>
    Gerrit-Comment-Date: Tue, 21 Aug 2018 20:10:50 +0000
    Gerrit-HasComments: No
    Gerrit-Has-Labels: No
    Gerrit-MessageType: comment

    Gobot Gobot (Gerrit)

    unread,
    Aug 21, 2018, 4:15:36 PM8/21/18
    to Ilya Tocar, goph...@pubsubhelper.golang.org, golang-co...@googlegroups.com

    Build is still in progress...
    This change failed on misc-compile-plan9:
    See https://storage.googleapis.com/go-build-log/798d6eb8/misc-compile-plan9_ab2d097e.log

    Consult https://build.golang.org/ to see whether it's a new failure. Other builds still in progress; subsequent failure notices suppressed until final report.

    View Change

      To view, visit change 130515. To unsubscribe, or for help writing mail filters, visit settings.

      Gerrit-Project: go
      Gerrit-Branch: master
      Gerrit-Change-Id: I2836f779b88bf8876d5fa725043a6042bdda0390
      Gerrit-Change-Number: 130515
      Gerrit-PatchSet: 1
      Gerrit-Owner: Ilya Tocar <ilya....@intel.com>
      Gerrit-Reviewer: Ilya Tocar <ilya....@intel.com>
      Gerrit-CC: Gobot Gobot <go...@golang.org>
      Gerrit-Comment-Date: Tue, 21 Aug 2018 20:15:34 +0000

      Gobot Gobot (Gerrit)

      unread,
      Aug 21, 2018, 4:19:15 PM8/21/18
      to Ilya Tocar, goph...@pubsubhelper.golang.org, golang-co...@googlegroups.com

      1 of 19 TryBots failed:
      Failed on misc-compile-plan9: https://storage.googleapis.com/go-build-log/798d6eb8/misc-compile-plan9_ab2d097e.log

      Consult https://build.golang.org/ to see whether they are new failures.

      Patch set 1:TryBot-Result -1

      View Change

        To view, visit change 130515. To unsubscribe, or for help writing mail filters, visit settings.

        Gerrit-Project: go
        Gerrit-Branch: master
        Gerrit-Change-Id: I2836f779b88bf8876d5fa725043a6042bdda0390
        Gerrit-Change-Number: 130515
        Gerrit-PatchSet: 1
        Gerrit-Owner: Ilya Tocar <ilya....@intel.com>
        Gerrit-Reviewer: Gobot Gobot <go...@golang.org>
        Gerrit-Reviewer: Ilya Tocar <ilya....@intel.com>
        Gerrit-Comment-Date: Tue, 21 Aug 2018 20:19:13 +0000
        Gerrit-HasComments: No
        Gerrit-Has-Labels: Yes
        Gerrit-MessageType: comment

        Ilya Tocar (Gerrit)

        unread,
        Aug 21, 2018, 4:34:21 PM8/21/18
        to Gobot Gobot, goph...@pubsubhelper.golang.org, golang-co...@googlegroups.com

        Ilya Tocar uploaded patch set #2 to this change.

        View Change

        net: use internal/bytealg insetad of linkname tricks

        We are currently using go:linkname for some algorithms from
        strings/bytes packages, to avoid importing strings/bytes.
        But strings/bytes are just wrappers around internal/bytealg, so
        we should use internal/bytealg directly.

        Change-Id: I2836f779b88bf8876d5fa725043a6042bdda0390
        ---
        M src/net/conf.go
        M src/net/dnsconfig_unix.go
        M src/net/hosts.go
        M src/net/ip.go
        M src/net/ipsock.go
        M src/net/ipsock_plan9.go
        M src/net/lookup_plan9.go

        M src/net/lookup_unix.go
        M src/net/nss.go
        M src/net/parse.go
        M src/net/port_unix.go
        M src/net/sockopt_posix.go
        12 files changed, 46 insertions(+), 50 deletions(-)

        To view, visit change 130515. To unsubscribe, or for help writing mail filters, visit settings.

        Gerrit-Project: go
        Gerrit-Branch: master
        Gerrit-Change-Id: I2836f779b88bf8876d5fa725043a6042bdda0390
        Gerrit-Change-Number: 130515
        Gerrit-PatchSet: 2
        Gerrit-Owner: Ilya Tocar <ilya....@intel.com>
        Gerrit-Reviewer: Gobot Gobot <go...@golang.org>
        Gerrit-Reviewer: Ilya Tocar <ilya....@intel.com>
        Gerrit-MessageType: newpatchset

        Gobot Gobot (Gerrit)

        unread,
        Aug 21, 2018, 4:34:32 PM8/21/18
        to Ilya Tocar, goph...@pubsubhelper.golang.org, golang-co...@googlegroups.com

        TryBots beginning. Status page: https://farmer.golang.org/try?commit=19d483ec

        View Change

          To view, visit change 130515. To unsubscribe, or for help writing mail filters, visit settings.

          Gerrit-Project: go
          Gerrit-Branch: master
          Gerrit-Change-Id: I2836f779b88bf8876d5fa725043a6042bdda0390
          Gerrit-Change-Number: 130515
          Gerrit-PatchSet: 2
          Gerrit-Owner: Ilya Tocar <ilya....@intel.com>
          Gerrit-Reviewer: Gobot Gobot <go...@golang.org>
          Gerrit-Reviewer: Ilya Tocar <ilya....@intel.com>
          Gerrit-Comment-Date: Tue, 21 Aug 2018 20:34:30 +0000

          Gobot Gobot (Gerrit)

          unread,
          Aug 21, 2018, 4:43:08 PM8/21/18
          to Ilya Tocar, goph...@pubsubhelper.golang.org, golang-co...@googlegroups.com

          TryBots are happy.

          Patch set 2:TryBot-Result +1

          View Change

            To view, visit change 130515. To unsubscribe, or for help writing mail filters, visit settings.

            Gerrit-Project: go
            Gerrit-Branch: master
            Gerrit-Change-Id: I2836f779b88bf8876d5fa725043a6042bdda0390
            Gerrit-Change-Number: 130515
            Gerrit-PatchSet: 2
            Gerrit-Owner: Ilya Tocar <ilya....@intel.com>
            Gerrit-Reviewer: Gobot Gobot <go...@golang.org>
            Gerrit-Reviewer: Ilya Tocar <ilya....@intel.com>
            Gerrit-Comment-Date: Tue, 21 Aug 2018 20:43:05 +0000

            Brad Fitzpatrick (Gerrit)

            unread,
            Aug 21, 2018, 4:55:56 PM8/21/18
            to Ilya Tocar, goph...@pubsubhelper.golang.org, Ian Lance Taylor, Brad Fitzpatrick, Gobot Gobot, golang-co...@googlegroups.com

            I'm okay with this, but Ian might have opinions.

            Let him weigh in first.

            Patch set 2:Code-Review +2

            View Change

              To view, visit change 130515. To unsubscribe, or for help writing mail filters, visit settings.

              Gerrit-Project: go
              Gerrit-Branch: master
              Gerrit-Change-Id: I2836f779b88bf8876d5fa725043a6042bdda0390
              Gerrit-Change-Number: 130515
              Gerrit-PatchSet: 2
              Gerrit-Owner: Ilya Tocar <ilya....@intel.com>
              Gerrit-Reviewer: Brad Fitzpatrick <brad...@golang.org>
              Gerrit-Reviewer: Gobot Gobot <go...@golang.org>
              Gerrit-Reviewer: Ian Lance Taylor <ia...@golang.org>
              Gerrit-Reviewer: Ilya Tocar <ilya....@intel.com>
              Gerrit-Comment-Date: Tue, 21 Aug 2018 20:55:54 +0000

              Ian Lance Taylor (Gerrit)

              unread,
              Aug 21, 2018, 6:08:50 PM8/21/18
              to Ilya Tocar, goph...@pubsubhelper.golang.org, Brad Fitzpatrick, Gobot Gobot, golang-co...@googlegroups.com

              LGTM. Thanks.

              Patch set 2:Code-Review +2

              View Change

                To view, visit change 130515. To unsubscribe, or for help writing mail filters, visit settings.

                Gerrit-Project: go
                Gerrit-Branch: master
                Gerrit-Change-Id: I2836f779b88bf8876d5fa725043a6042bdda0390
                Gerrit-Change-Number: 130515
                Gerrit-PatchSet: 2
                Gerrit-Owner: Ilya Tocar <ilya....@intel.com>
                Gerrit-Reviewer: Brad Fitzpatrick <brad...@golang.org>
                Gerrit-Reviewer: Gobot Gobot <go...@golang.org>
                Gerrit-Reviewer: Ian Lance Taylor <ia...@golang.org>
                Gerrit-Reviewer: Ilya Tocar <ilya....@intel.com>
                Gerrit-Comment-Date: Tue, 21 Aug 2018 22:08:48 +0000

                Brad Fitzpatrick (Gerrit)

                unread,
                Aug 21, 2018, 6:09:26 PM8/21/18
                to Ilya Tocar, Brad Fitzpatrick, goph...@pubsubhelper.golang.org, golang-...@googlegroups.com, Ian Lance Taylor, Gobot Gobot, golang-co...@googlegroups.com

                Brad Fitzpatrick merged this change.

                View Change

                Approvals: Brad Fitzpatrick: Looks good to me, approved Ian Lance Taylor: Looks good to me, approved Ilya Tocar: Run TryBots Gobot Gobot: TryBots succeeded
                net: use internal/bytealg insetad of linkname tricks

                We are currently using go:linkname for some algorithms from
                strings/bytes packages, to avoid importing strings/bytes.
                But strings/bytes are just wrappers around internal/bytealg, so
                we should use internal/bytealg directly.

                Change-Id: I2836f779b88bf8876d5fa725043a6042bdda0390
                Reviewed-on: https://go-review.googlesource.com/130515
                Run-TryBot: Ilya Tocar <ilya....@intel.com>
                TryBot-Result: Gobot Gobot <go...@golang.org>
                Reviewed-by: Brad Fitzpatrick <brad...@golang.org>
                Reviewed-by: Ian Lance Taylor <ia...@golang.org>

                ---
                M src/net/conf.go
                M src/net/dnsconfig_unix.go
                M src/net/hosts.go
                M src/net/ip.go
                M src/net/ipsock.go
                M src/net/ipsock_plan9.go
                M src/net/lookup_plan9.go

                M src/net/lookup_unix.go
                M src/net/nss.go
                M src/net/parse.go
                M src/net/port_unix.go
                M src/net/sockopt_posix.go
                12 files changed, 46 insertions(+), 50 deletions(-)

                diff --git a/src/net/ipsock_plan9.go b/src/net/ipsock_plan9.go
                index 312e4ad..d226585 100644
                --- a/src/net/ipsock_plan9.go
                +++ b/src/net/ipsock_plan9.go

                @@ -6,6 +6,7 @@

                import (
                "context"
                + "internal/bytealg"
                 	"os"
                "syscall"
                )
                @@ -49,7 +50,7 @@
                // parsePlan9Addr parses address of the form [ip!]port (e.g. 127.0.0.1!80).
                func parsePlan9Addr(s string) (ip IP, iport int, err error) {
                addr := IPv4zero // address contains port only
                - i := byteIndex(s, '!')
                + i := bytealg.IndexByteString(s, '!')
                if i >= 0 {
                addr = ParseIP(s[:i])
                if addr == nil {
                diff --git a/src/net/lookup_plan9.go b/src/net/lookup_plan9.go
                index 5547f0b..d5ae9b2 100644
                --- a/src/net/lookup_plan9.go
                +++ b/src/net/lookup_plan9.go
                @@ -7,6 +7,7 @@
                import (
                "context"

                "errors"
                + "internal/bytealg"
                "io"
                "os"
                )
                @@ -135,7 +136,7 @@
                return 0, UnknownNetworkError(name)
                }
                s := f[1]
                - if n, _, ok := dtoi(s[byteIndex(s, '=')+1:]); ok {
                + if n, _, ok := dtoi(s[bytealg.IndexByteString(s, '=')+1:]); ok {
                return n, nil
                }
                return 0, UnknownNetworkError(name)
                @@ -158,7 +159,7 @@
                continue
                }
                addr := f[1]
                - if i := byteIndex(addr, '!'); i >= 0 {
                + if i := bytealg.IndexByteString(addr, '!'); i >= 0 {
                addr = addr[:i] // remove port
                }
                if ParseIP(addr) == nil {
                @@ -210,7 +211,7 @@
                return 0, unknownPortError
                }
                s := f[1]
                - if i := byteIndex(s, '!'); i >= 0 {
                + if i := bytealg.IndexByteString(s, '!'); i >= 0 {
                s = s[i+1:] // remove address
                }
                if n, _, ok := dtoi(s); ok {
                @@ -304,7 +305,7 @@
                return
                }
                for _, line := range lines {
                - if i := byteIndex(line, '\t'); i >= 0 {
                + if i := bytealg.IndexByteString(line, '\t'); i >= 0 {
                txt = append(txt, absDomainName([]byte(line[i+1:])))
                Gerrit-PatchSet: 3
                Gerrit-Owner: Ilya Tocar <ilya....@intel.com>
                Gerrit-Reviewer: Brad Fitzpatrick <brad...@golang.org>
                Gerrit-Reviewer: Gobot Gobot <go...@golang.org>
                Gerrit-Reviewer: Ian Lance Taylor <ia...@golang.org>
                Gerrit-Reviewer: Ilya Tocar <ilya....@intel.com>
                Gerrit-MessageType: merged
                Reply all
                Reply to author
                Forward
                0 new messages