From: vovapi Date: Fri, 17 Jan 2020 16:38:39 +0000 (+0000) Subject: go/constant: remove redundant octal & separator literals parsing X-Git-Tag: go1.15beta1~1154 X-Git-Url: http://www.git.cypherpunks.su/?a=commitdiff_plain;h=7f41a009a6d3f37c336b8e01fea90f11f996ce9a;p=gostls13.git go/constant: remove redundant octal & separator literals parsing Octal literals parsing was implemented in strconv in golang.org/cl/160244 and in math/big in golang.org/cl/165898. Underscore separator parsing was implemented in strconv in golang.org/cl/160243 and in math/big golang.org/cl/166157. Thus octal & underscore literal parsing in go/constant is removed as redundant. This CL resolves TODO left by gri in golang.org/cl/160239 . Change-Id: I311872dac49b1a13063e0abc1794001956620c5a GitHub-Last-Rev: 264caf574e8dee8f1e36d9e62edb0ee3ff60d2d1 GitHub-Pull-Request: golang/go#36630 Reviewed-on: https://go-review.googlesource.com/c/go/+/215277 Run-TryBot: Ian Lance Taylor Run-TryBot: Robert Griesemer Reviewed-by: Robert Griesemer --- diff --git a/src/go/constant/value.go b/src/go/constant/value.go index cd77b376d1..08bcb3bf87 100644 --- a/src/go/constant/value.go +++ b/src/go/constant/value.go @@ -381,17 +381,8 @@ func MakeFromLiteral(lit string, tok token.Token, zero uint) Value { panic("MakeFromLiteral called with non-zero last argument") } - // TODO(gri) Remove stripSep and, for token.INT, 0o-octal handling - // below once strconv and math/big can handle separators - // and 0o-octals. - switch tok { case token.INT: - // TODO(gri) remove 0o-special case once strconv and math/big can handle 0o-octals - lit = stripSep(lit) - if len(lit) >= 2 && lit[0] == '0' && (lit[1] == 'o' || lit[1] == 'O') { - lit = "0" + lit[2:] - } if x, err := strconv.ParseInt(lit, 0, 64); err == nil { return int64Val(x) } @@ -400,13 +391,11 @@ func MakeFromLiteral(lit string, tok token.Token, zero uint) Value { } case token.FLOAT: - lit = stripSep(lit) if x := makeFloatFromLiteral(lit); x != nil { return x } case token.IMAG: - lit = stripSep(lit) if n := len(lit); n > 0 && lit[n-1] == 'i' { if im := makeFloatFromLiteral(lit[:n-1]); im != nil { return makeComplex(int64Val(0), im) @@ -432,26 +421,6 @@ func MakeFromLiteral(lit string, tok token.Token, zero uint) Value { return unknownVal{} } -func stripSep(s string) string { - // avoid making a copy if there are no separators (common case) - i := 0 - for i < len(s) && s[i] != '_' { - i++ - } - if i == len(s) { - return s - } - - // make a copy of s without separators - var buf []byte - for i := 0; i < len(s); i++ { - if c := s[i]; c != '_' { - buf = append(buf, c) - } - } - return string(buf) -} - // ---------------------------------------------------------------------------- // Accessors //