mirror of
https://github.com/golang/go
synced 2024-11-19 02:14:43 -07:00
go/printer: use append
R=rsc CC=golang-dev https://golang.org/cl/2793041
This commit is contained in:
parent
098e94173a
commit
fafb116c75
@ -10,7 +10,6 @@ package printer
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"container/vector"
|
|
||||||
"go/ast"
|
"go/ast"
|
||||||
"go/token"
|
"go/token"
|
||||||
)
|
)
|
||||||
@ -718,23 +717,20 @@ func splitSelector(expr ast.Expr) (body, suffix ast.Expr) {
|
|||||||
|
|
||||||
// Convert an expression into an expression list split at the periods of
|
// Convert an expression into an expression list split at the periods of
|
||||||
// selector expressions.
|
// selector expressions.
|
||||||
func selectorExprList(expr ast.Expr) []ast.Expr {
|
func selectorExprList(expr ast.Expr) (list []ast.Expr) {
|
||||||
// split expression
|
// split expression
|
||||||
var list vector.Vector
|
|
||||||
for expr != nil {
|
for expr != nil {
|
||||||
var suffix ast.Expr
|
var suffix ast.Expr
|
||||||
expr, suffix = splitSelector(expr)
|
expr, suffix = splitSelector(expr)
|
||||||
list.Push(suffix)
|
list = append(list, suffix)
|
||||||
}
|
}
|
||||||
|
|
||||||
// convert expression list
|
// reverse list
|
||||||
result := make([]ast.Expr, len(list))
|
for i, j := 0, len(list)-1; i < j; i, j = i+1, j-1 {
|
||||||
i := len(result)
|
list[i], list[j] = list[j], list[i]
|
||||||
for _, x := range list {
|
|
||||||
i--
|
|
||||||
result[i] = x.(ast.Expr)
|
|
||||||
}
|
}
|
||||||
return result
|
|
||||||
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user