new new & make

R=r
OCL=22166
CL=22166
This commit is contained in:
Russ Cox 2009-01-06 15:19:02 -08:00
parent 9662e7b2db
commit 5564504507
113 changed files with 363 additions and 364 deletions

View file

@ -625,7 +625,7 @@ func (v *FixedArrayValueStruct) Elem(i int) Value {
func ArrayCreator(typ Type, addr Addr) Value {
arraytype := typ.(ArrayType);
if arraytype.Open() {
v := new(*OpenArrayValueStruct);
v := new(OpenArrayValueStruct);
v.kind = ArrayKind;
v.addr = addr;
v.typ = typ;
@ -634,7 +634,7 @@ func ArrayCreator(typ Type, addr Addr) Value {
v.array = addr.(*RuntimeArray);
return v;
}
v := new(*FixedArrayValueStruct);
v := new(FixedArrayValueStruct);
v.kind = ArrayKind;
v.addr = addr;
v.typ = typ;
@ -710,7 +710,7 @@ func (v *StructValueStruct) Field(i int) Value {
func StructCreator(typ Type, addr Addr) Value {
t := typ.(StructType);
nfield := t.Len();
v := &StructValueStruct{ Common{StructKind, typ, addr}, new([]Value, nfield) };
v := &StructValueStruct{ Common{StructKind, typ, addr}, make([]Value, nfield) };
for i := 0; i < nfield; i++ {
name, ftype, str, offset := t.Field(i);
addr_uint := uintptr(addr) + uintptr(offset);
@ -783,7 +783,7 @@ var creator = map[int] Creator {
FuncKind : &FuncCreator,
}
var typecache = new(map[string] *Type);
var typecache = make(map[string] *Type);
func NewValueAddr(typ Type, addr Addr) Value {
c, ok := creator[typ.Kind()];
@ -807,7 +807,7 @@ export func NewInitValue(typ Type) Value {
if size == 0 {
size = 1;
}
data := new([]uint8, size);
data := make([]uint8, size);
return NewValueAddr(typ, Addr(&data[0]));
}
@ -824,12 +824,12 @@ export func NewOpenArrayValue(typ ArrayType, len, cap int) ArrayValue {
return nil
}
array := new(*RuntimeArray);
array := new(RuntimeArray);
size := typ.Elem().Size() * cap;
if size == 0 {
size = 1;
}
data := new([]uint8, size);
data := make([]uint8, size);
array.data = Addr(&data[0]);
array.len = uint32(len);
array.cap = uint32(cap);
@ -874,13 +874,13 @@ export func NewValue(e interface {}) Value {
p, ok := typecache[typestring];
if !ok {
typ := ParseTypeString("", typestring);
p = new(*Type);
p = new(Type);
*p = typ;
typecache[typestring] = p;
}
// Content of interface is a value; need a permanent copy to take its address
// so we can modify the contents. Values contain pointers to 'values'.
ap := new(*uint64);
ap := new(uint64);
*ap = value;
return NewValueAddr(*p, ap.(Addr));
}