Rename [i:j] to [i .. j], the same as Rust

This commit is contained in:
Nigel Tao committed 2019-10-12 21:14:18 +11:00
1 parent 7872a8893b
commit a9ea63ff06
16 files changed
+55 -50

No files matched your search

+4 -4
View File
@@ -434,7 +434,7 @@ func (g *gen) writeBuiltinSlice(b *buffer, recv *a.Expr, method t.ID, args []*a.
// writeBuiltinSliceCopyFromSlice8 writes an optimized version of:
//
// foo[fIndex:fIndex + 8].copy_from_slice!(s:bar[bIndex:bIndex + 8])
// foo[fIndex .. fIndex + 8].copy_from_slice!(s:bar[bIndex .. bIndex + 8])
func (g *gen) writeBuiltinSliceCopyFromSlice8(b *buffer, recv *a.Expr, method t.ID, args []*a.Node, depth uint32) error {
if method != t.IDCopyFromSlice || len(args) != 1 {
return errOptimizationNotApplicable
@@ -475,10 +475,10 @@ func (g *gen) writeBuiltinSliceCopyFromSlice8(b *buffer, recv *a.Expr, method t.
return nil
}
// matchFooIndexIndexPlus8 matches n with "foo[index:index + 8]" or "foo[:8]".
// It returns a nil foo if there isn't a match.
// matchFooIndexIndexPlus8 matches n with "foo[index .. index + 8]" or "foo[..
// 8]". It returns a nil foo if there isn't a match.
func matchFooIndexIndexPlus8(n *a.Expr) (foo *a.Expr, index *a.Expr) {
if n.Operator() != t.IDColon {
if n.Operator() != t.IDDotDot {
return nil, nil
}
foo = n.LHS().AsExpr()
+1 -1
View File
@@ -148,7 +148,7 @@ func (g *gen) writeExprOther(b *buffer, n *a.Expr, depth uint32) error {
b.writeb(']')
return nil
case t.IDColon:
case t.IDDotDot:
// n is a slice.
lhs := n.LHS().AsExpr()
mhs := n.MHS().AsExpr()