]> Cypherpunks repositories - gostls13.git/commitdiff
change reflect.CopyArray into a method on ArrayValue called CopyFrom
authorRob Pike <r@golang.org>
Wed, 21 Jan 2009 23:45:54 +0000 (15:45 -0800)
committerRob Pike <r@golang.org>
Wed, 21 Jan 2009 23:45:54 +0000 (15:45 -0800)
R=rsc
DELTA=16  (12 added, 0 deleted, 4 changed)
OCL=23242
CL=23242

src/lib/json/struct.go
src/lib/reflect/all_test.go
src/lib/reflect/value.go

index 167fcbff0f5d9be2fa9e1c0afa88de13c9e49c78..0d0c1476e7c47024f477544221c7ab22d35837e3 100644 (file)
@@ -149,7 +149,7 @@ func (b *_StructBuilder) Elem(i int) Builder {
                                        n *= 2
                                }
                                av1 := reflect.NewOpenArrayValue(av.Type(), av.Len(), n);
-                               reflect.CopyArray(av1, av, av.Len());
+                               av1.CopyFrom(av, av.Len());
                                pv.SetSub(av1);
                                av = av1;
                        }
index 631a5662c47274dc33d5d1a831f10d65f8770f7b..f991110a8d54b7508108ed27609f98a8f6f6ec7e 100644 (file)
@@ -308,7 +308,7 @@ func TestCopyArray(t *testing.T) {
                }
        }
        for tocopy := 1; tocopy <= 7; tocopy++ {
-               CopyArray(vb.(PtrValue).Sub(), va.(PtrValue).Sub(), tocopy);
+               vb.(PtrValue).Sub().(ArrayValue).CopyFrom(va.(PtrValue).Sub(), tocopy);
                for i := 0; i < tocopy; i++ {
                        if a[i] != b[i] {
                                t.Errorf("1 tocopy=%d a[%d]=%d, b[%d]=%d",
index f1651a28c87db69e4cc5b36153e82123cd94a84d..6fd4fe24583a51a1ad8b7df65546e2e4e32767ce 100644 (file)
@@ -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
        }