diff options
author | ian <ian@138bc75d-0d04-0410-961f-82ee72b054a4> | 2012-02-09 08:19:58 +0000 |
---|---|---|
committer | ian <ian@138bc75d-0d04-0410-961f-82ee72b054a4> | 2012-02-09 08:19:58 +0000 |
commit | 2da6f72bb78de6e6ca3d387d970cb21bf36684be (patch) | |
tree | 7ca86535c5a6b99d4cc432ba5cfddabc5ee4ea16 /libgo/go/encoding/binary/binary.go | |
parent | 98ea39f2b59cc0a4a0a32b095e8f0faa84fd7882 (diff) | |
download | gcc-2da6f72bb78de6e6ca3d387d970cb21bf36684be.tar.gz |
libgo: Update to weekly.2012-02-07.
git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@184034 138bc75d-0d04-0410-961f-82ee72b054a4
Diffstat (limited to 'libgo/go/encoding/binary/binary.go')
-rw-r--r-- | libgo/go/encoding/binary/binary.go | 10 |
1 files changed, 7 insertions, 3 deletions
diff --git a/libgo/go/encoding/binary/binary.go b/libgo/go/encoding/binary/binary.go index d2f8b1e6248..4be83f53bd4 100644 --- a/libgo/go/encoding/binary/binary.go +++ b/libgo/go/encoding/binary/binary.go @@ -163,7 +163,7 @@ func Read(r io.Reader, order ByteOrder, data interface{}) error { default: return errors.New("binary.Read: invalid type " + d.Type().String()) } - size := TotalSize(v) + size := dataSize(v) if size < 0 { return errors.New("binary.Read: invalid type " + v.Type().String()) } @@ -242,7 +242,7 @@ func Write(w io.Writer, order ByteOrder, data interface{}) error { return err } v := reflect.Indirect(reflect.ValueOf(data)) - size := TotalSize(v) + size := dataSize(v) if size < 0 { return errors.New("binary.Write: invalid type " + v.Type().String()) } @@ -253,7 +253,11 @@ func Write(w io.Writer, order ByteOrder, data interface{}) error { return err } -func TotalSize(v reflect.Value) int { +// dataSize returns the number of bytes the actual data represented by v occupies in memory. +// For compound structures, it sums the sizes of the elements. Thus, for instance, for a slice +// it returns the length of the slice times the element size and does not count the memory +// occupied by the header. +func dataSize(v reflect.Value) int { if v.Kind() == reflect.Slice { elem := sizeof(v.Type().Elem()) if elem < 0 { |