]> Cypherpunks repositories - gostls13.git/commitdiff
go/constant: remove redundant octal & separator literals parsing
authorvovapi <evgrafov.vladimir@gmail.com>
Fri, 17 Jan 2020 16:38:39 +0000 (16:38 +0000)
committerRobert Griesemer <gri@golang.org>
Fri, 21 Feb 2020 18:34:54 +0000 (18:34 +0000)
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 <iant@golang.org>
Run-TryBot: Robert Griesemer <gri@golang.org>
Reviewed-by: Robert Griesemer <gri@golang.org>
src/go/constant/value.go

index cd77b376d12a946fcf85fe9b0ad976356dc6eeee..08bcb3bf8719d641ad12e31df4600ae5fa5ee0be 100644 (file)
@@ -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
 //