summaryrefslogtreecommitdiff
path: root/src/lib/reflect/value.go
diff options
context:
space:
mode:
authorRob Pike <r@golang.org>2009-01-21 15:45:54 -0800
committerRob Pike <r@golang.org>2009-01-21 15:45:54 -0800
commitbc1696eb57e876c74d00b5f5512e05956f915ea8 (patch)
tree09f748a5a997f8f6e2885e2a348b95a199c1d4fc /src/lib/reflect/value.go
parentde19ab2132fa386fba9ab28cea1c393debf6bf9c (diff)
downloadgolang-bc1696eb57e876c74d00b5f5512e05956f915ea8.tar.gz
change reflect.CopyArray into a method on ArrayValue called CopyFrom
R=rsc DELTA=16 (12 added, 0 deleted, 4 changed) OCL=23242 CL=23242
Diffstat (limited to 'src/lib/reflect/value.go')
-rw-r--r--src/lib/reflect/value.go14
1 files changed, 13 insertions, 1 deletions
diff --git a/src/lib/reflect/value.go b/src/lib/reflect/value.go
index f1651a28c..6fd4fe245 100644
--- a/src/lib/reflect/value.go
+++ b/src/lib/reflect/value.go
@@ -553,8 +553,11 @@ type ArrayValue interface {
Cap() int;
Elem(i int) Value;
SetLen(len int);
+ CopyFrom(src ArrayValue, n int)
}
+func copyArray(dst ArrayValue, src ArrayValue, n int);
+
/*
Run-time representation of open arrays looks like this:
struct Array {
@@ -600,6 +603,10 @@ func (v *openArrayValueStruct) Elem(i int) Value {
return newValueAddr(v.elemtype, Addr(data_uint));
}
+func (v *openArrayValueStruct) CopyFrom(src ArrayValue, n int) {
+ copyArray(v, src, n);
+}
+
type fixedArrayValueStruct struct {
commonValue;
elemtype Type;
@@ -628,6 +635,10 @@ func (v *fixedArrayValueStruct) Elem(i int) Value {
return nil
}
+func (v *fixedArrayValueStruct) CopyFrom(src ArrayValue, n int) {
+ copyArray(v, src, n);
+}
+
func arrayCreator(typ Type, addr Addr) Value {
arraytype := typ.(ArrayType);
if arraytype.Open() {
@@ -843,7 +854,8 @@ func NewOpenArrayValue(typ ArrayType, len, cap int) ArrayValue {
return newValueAddr(typ, Addr(array));
}
-func CopyArray(dst ArrayValue, src ArrayValue, n int) {
+// Works on both fixed and open arrays.
+func copyArray(dst ArrayValue, src ArrayValue, n int) {
if n == 0 {
return
}