]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/compile: cleanup alg.go for Field slices
authorMatthew Dempsky <mdempsky@google.com>
Mon, 28 Mar 2016 17:35:13 +0000 (10:35 -0700)
committerMatthew Dempsky <mdempsky@google.com>
Mon, 28 Mar 2016 20:13:59 +0000 (20:13 +0000)
Passes toolstash -cmp.

Change-Id: Ie41d7e74847c44a8fd174731374339c6c32b1460
Reviewed-on: https://go-review.googlesource.com/21231
Run-TryBot: Matthew Dempsky <mdempsky@google.com>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
src/cmd/compile/internal/gc/alg.go
src/cmd/compile/internal/gc/align.go
src/cmd/compile/internal/gc/type.go

index eb6bacf901f126a7d8923df2da5cbabfdffb0f40..ac5156124e16a5874edd89cc4e4f9a07eeb5aa87 100644 (file)
@@ -146,7 +146,7 @@ func algtype1(t *Type, bad **Type) int {
 
                        // Blank fields, padded fields, fields with non-memory
                        // equality need special compare.
-                       if a != AMEM || isblanksym(f.Sym) || ispaddedfield(t, fields, i) {
+                       if a != AMEM || isblanksym(f.Sym) || ispaddedfield(t, i) {
                                ret = -1
                        }
                }
@@ -253,7 +253,7 @@ func genhash(sym *Sym, t *Type) {
                        }
 
                        // Otherwise, hash a maximal length run of raw memory.
-                       size, next := memrun(t, fields, i)
+                       size, next := memrun(t, i)
 
                        // h = hashel(&p.first, size, h)
                        hashel := hashmem(f.Type)
@@ -442,7 +442,7 @@ func geneq(sym *Sym, t *Type) {
                        }
 
                        // Find maximal length run of memory-only fields.
-                       size, next := memrun(t, fields, i)
+                       size, next := memrun(t, i)
 
                        // TODO(rsc): All the calls to newname are wrong for
                        // cross-package unexported fields.
@@ -546,40 +546,36 @@ func eqmemfunc(size int64, t *Type) (fn *Node, needsize bool) {
 
 // memrun finds runs of struct fields for which memory-only algs are appropriate.
 // t is the parent struct type, and start is the field index at which to start the run.
-// The caller is responsible for providing t.FieldSlice() as fields.
 // size is the length in bytes of the memory included in the run.
 // next is the index just after the end of the memory run.
-// TODO(mdempsky): Eliminate fields parameter once struct fields are kept in slices.
-func memrun(t *Type, fields []*Field, start int) (size int64, next int) {
+func memrun(t *Type, start int) (size int64, next int) {
        next = start
        for {
                next++
-               if next == len(fields) {
+               if next == t.NumFields() {
                        break
                }
                // Stop run after a padded field.
-               if ispaddedfield(t, fields, next-1) {
+               if ispaddedfield(t, next-1) {
                        break
                }
                // Also, stop before a blank or non-memory field.
-               if isblanksym(fields[next].Sym) || algtype1(fields[next].Type, nil) != AMEM {
+               if f := t.Field(next); isblanksym(f.Sym) || algtype1(f.Type, nil) != AMEM {
                        break
                }
        }
-       end := fields[next-1].Offset + fields[next-1].Type.Width
-       return end - fields[start].Offset, next
+       return t.Field(next-1).End() - t.Field(start).Offset, next
 }
 
 // ispaddedfield reports whether the i'th field of struct type t is followed
-// by padding. The caller is responsible for providing t.FieldSlice() as fields.
-// TODO(mdempsky): Eliminate fields parameter once struct fields are kept in slices.
-func ispaddedfield(t *Type, fields []*Field, i int) bool {
+// by padding.
+func ispaddedfield(t *Type, i int) bool {
        if t.Etype != TSTRUCT {
                Fatalf("ispaddedfield called non-struct %v", t)
        }
        end := t.Width
-       if i+1 < len(fields) {
-               end = fields[i+1].Offset
+       if i+1 < t.NumFields() {
+               end = t.Field(i + 1).Offset
        }
-       return fields[i].Offset+fields[i].Type.Width != end
+       return t.Field(i).End() != end
 }
index 50bb05a367a74fb6b4bd454ab85dcd0fd485594c..dd508a508f9cbac51856fe74058911d35c2df161 100644 (file)
@@ -388,7 +388,7 @@ func Argsize(t *Type) int {
 
        for _, p := range recvsParamsResults {
                for _, f := range p(t).Fields().Slice() {
-                       if x := f.Offset + f.Type.Width; x > w {
+                       if x := f.End(); x > w {
                                w = x
                        }
                }
index b9d74592e8df903f6808e874eb03e2e5831dcb0e..f8a436c65540161714cae17e6ba33934273a4173 100644 (file)
@@ -175,6 +175,11 @@ type Field struct {
        Note *string // literal string annotation
 }
 
+// End returns the offset of the first byte immediately after this field.
+func (f *Field) End() int64 {
+       return f.Offset + f.Type.Width
+}
+
 // Fields is a pointer to a slice of *Field.
 // This saves space in Types that do not have fields or methods
 // compared to a simple slice of *Field.