Skip to content

Commit

Permalink
new new & make
Browse files Browse the repository at this point in the history
R=r
OCL=22166
CL=22166
  • Loading branch information
rsc committed Jan 6, 2009
1 parent 9662e7b commit 5564504
Show file tree
Hide file tree
Showing 113 changed files with 363 additions and 364 deletions.
26 changes: 13 additions & 13 deletions src/lib/bignum.go
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ func (x Natural) Add(y Natural) Natural {
}

c := Digit(0);
z := new(Natural, n + 1);
z := make(Natural, n + 1);
i := 0;
for i < m {
t := c + x[i] + y[i];
Expand Down Expand Up @@ -195,7 +195,7 @@ func (x Natural) Sub(y Natural) Natural {
}

c := Digit(0);
z := new(Natural, n);
z := make(Natural, n);
i := 0;
for i < m {
t := c + x[i] - y[i];
Expand Down Expand Up @@ -253,7 +253,7 @@ func (x Natural) Mul(y Natural) Natural {
n := len(x);
m := len(y);

z := new(Natural, n + m);
z := make(Natural, n + m);
for j := 0; j < m; j++ {
d := y[j];
if d != 0 {
Expand All @@ -280,7 +280,7 @@ func (x Natural) Mul(y Natural) Natural {

func Unpack(x Natural) []Digit2 {
n := len(x);
z := new([]Digit2, n*2 + 1); // add space for extra digit (used by DivMod)
z := make([]Digit2, n*2 + 1); // add space for extra digit (used by DivMod)
for i := 0; i < n; i++ {
t := x[i];
z[i*2] = Digit2(t & M2);
Expand All @@ -296,7 +296,7 @@ func Unpack(x Natural) []Digit2 {

func Pack(x []Digit2) Natural {
n := (len(x) + 1) / 2;
z := new(Natural, n);
z := make(Natural, n);
if len(x) & 1 == 1 {
// handle odd len(x)
n--;
Expand Down Expand Up @@ -472,7 +472,7 @@ func Shl(z, x []Digit, s uint) Digit {
func (x Natural) Shl(s uint) Natural {
n := uint(len(x));
m := n + s/W;
z := new(Natural, m+1);
z := make(Natural, m+1);

z[m] = Shl(z[m-n : m], x, s%W);

Expand All @@ -497,7 +497,7 @@ func (x Natural) Shr(s uint) Natural {
if m > n { // check for underflow
m = 0;
}
z := new(Natural, m);
z := make(Natural, m);

Shr(z, x[n-m : n], s%W);

Expand All @@ -512,7 +512,7 @@ func (x Natural) And(y Natural) Natural {
return y.And(x);
}

z := new(Natural, m);
z := make(Natural, m);
for i := 0; i < m; i++ {
z[i] = x[i] & y[i];
}
Expand All @@ -536,7 +536,7 @@ func (x Natural) Or(y Natural) Natural {
return y.Or(x);
}

z := new(Natural, n);
z := make(Natural, n);
for i := 0; i < m; i++ {
z[i] = x[i] | y[i];
}
Expand All @@ -553,7 +553,7 @@ func (x Natural) Xor(y Natural) Natural {
return y.Xor(x);
}

z := new(Natural, n);
z := make(Natural, n);
for i := 0; i < m; i++ {
z[i] = x[i] ^ y[i];
}
Expand Down Expand Up @@ -627,10 +627,10 @@ func (x Natural) ToString(base uint) string {
// allocate buffer for conversion
assert(2 <= base && base <= 16);
n := (x.Log2() + 1) / Log2(Digit(base)) + 1; // +1: round up
s := new([]byte, n);
s := make([]byte, n);

// don't destroy x
t := new(Natural, len(x));
t := make(Natural, len(x));
Copy(t, x);

// convert
Expand Down Expand Up @@ -681,7 +681,7 @@ func HexValue(ch byte) uint {
func MulAdd1(x Natural, d, c Digit) Natural {
assert(IsSmall(d-1) && IsSmall(c));
n := len(x);
z := new(Natural, n + 1);
z := make(Natural, n + 1);

for i := 0; i < n; i++ {
t := c + x[i]*d;
Expand Down
16 changes: 8 additions & 8 deletions src/lib/bufio.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,8 @@ export func NewBufReadSize(rd io.Read, size int) (b *BufRead, err *os.Error) {
if size <= 0 {
return nil, BadBufSize
}
b = new(*BufRead);
b.buf = new([]byte, size);
b = new(BufRead);
b.buf = make([]byte, size);
b.rd = rd;
return b, nil
}
Expand Down Expand Up @@ -262,7 +262,7 @@ func (b *BufRead) ReadLineBytes(delim byte) (line []byte, err *os.Error) {
}

// Read bytes out of buffer.
buf := new([]byte, b.Buffered());
buf := make([]byte, b.Buffered());
var n int;
n, e = b.Read(buf);
if e != nil {
Expand All @@ -278,9 +278,9 @@ func (b *BufRead) ReadLineBytes(delim byte) (line []byte, err *os.Error) {

// Grow list if needed.
if full == nil {
full = new([][]byte, 16);
full = make([][]byte, 16);
} else if nfull >= len(full) {
newfull := new([][]byte, len(full)*2);
newfull := make([][]byte, len(full)*2);
// BUG slice assignment
for i := 0; i < len(full); i++ {
newfull[i] = full[i];
Expand All @@ -301,7 +301,7 @@ func (b *BufRead) ReadLineBytes(delim byte) (line []byte, err *os.Error) {
n += len(frag);

// Copy full pieces and fragment in.
buf := new([]byte, n);
buf := make([]byte, n);
n = 0;
for i := 0; i < nfull; i++ {
CopySlice(buf[n:n+len(full[i])], full[i]);
Expand Down Expand Up @@ -339,8 +339,8 @@ export func NewBufWriteSize(wr io.Write, size int) (b *BufWrite, err *os.Error)
if size <= 0 {
return nil, BadBufSize
}
b = new(*BufWrite);
b.buf = new([]byte, size);
b = new(BufWrite);
b.buf = make([]byte, size);
b.wr = wr;
return b, nil
}
Expand Down
16 changes: 8 additions & 8 deletions src/lib/bufio_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import (
)

func StringToBytes(s string) []byte {
b := new([]byte, len(s));
b := make([]byte, len(s));
for i := 0; i < len(s); i++ {
b[i] = s[i]
}
Expand All @@ -34,7 +34,7 @@ type ByteReader struct {
}

func NewByteReader(p []byte) io.Read {
b := new(*ByteReader);
b := new(ByteReader);
b.p = p;
return b
}
Expand All @@ -56,7 +56,7 @@ type HalfByteReader struct {
}

func NewHalfByteReader(p []byte) io.Read {
b := new(*HalfByteReader);
b := new(HalfByteReader);
b.p = p;
return b
}
Expand All @@ -80,7 +80,7 @@ type Rot13Reader struct {
}

func NewRot13Reader(r io.Read) *Rot13Reader {
r13 := new(*Rot13Reader);
r13 := new(Rot13Reader);
r13.r = r;
return r13
}
Expand Down Expand Up @@ -238,14 +238,14 @@ type ByteWriter struct {
}

func NewByteWriter() WriteBuffer {
return new(*ByteWriter)
return new(ByteWriter)
}

func (w *ByteWriter) Write(p []byte) (int, *os.Error) {
if w.p == nil {
w.p = new([]byte, len(p)+100)
w.p = make([]byte, len(p)+100)
} else if w.n + len(p) >= len(w.p) {
newp := new([]byte, len(w.p)*2 + len(p));
newp := make([]byte, len(w.p)*2 + len(p));
Copy(newp[0:w.n], w.p[0:w.n]);
w.p = newp
}
Expand All @@ -266,7 +266,7 @@ type HalfByteWriter struct {
}

func NewHalfByteWriter() WriteBuffer {
w := new(*HalfByteWriter);
w := new(HalfByteWriter);
w.bw = NewByteWriter();
return w
}
Expand Down
6 changes: 3 additions & 3 deletions src/lib/container/array/array.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ func (p *Array) Init(initial_len int) *Array {
if initial_len > n {
n = initial_len
}
a = new([]Element, n);
a = make([]Element, n);
} else {
// nil out entries
for j := len(a) - 1; j >= 0; j-- {
Expand All @@ -36,7 +36,7 @@ func (p *Array) Init(initial_len int) *Array {


export func New(len int) *Array {
return new(*Array).Init(len)
return new(Array).Init(len)
}


Expand Down Expand Up @@ -66,7 +66,7 @@ func (p *Array) Insert(i int, x Element) {

// grow array by doubling its capacity
if n == cap(a) {
b := new([]Element, 2*n);
b := make([]Element, 2*n);
for j := n-1; j >= 0; j-- {
b[j] = a[j];
}
Expand Down
2 changes: 1 addition & 1 deletion src/lib/container/array/intarray.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ func (p *IntArray) Init(len int) *IntArray {


export func NewIntArray(len int) *IntArray {
return new(*IntArray).Init(len)
return new(IntArray).Init(len)
}


Expand Down
8 changes: 4 additions & 4 deletions src/lib/flag.go
Original file line number Diff line number Diff line change
Expand Up @@ -318,10 +318,10 @@ func (f *Flag) SVal() string {
}

func New() *Flags {
f := new(*Flags);
f := new(Flags);
f.first_arg = 1; // 0 is the program name, 1 is first arg
f.actual = new(map[string] *Flag);
f.formal = new(map[string] *Flag);
f.actual = make(map[string] *Flag);
f.formal = make(map[string] *Flag);
return f;
}

Expand Down Expand Up @@ -361,7 +361,7 @@ export func NArg() int {
}

func Add(name string, value Value, usage string) *Flag {
f := new(*Flag);
f := new(Flag);
f.name = name;
f.usage = usage;
f.value = value;
Expand Down
4 changes: 2 additions & 2 deletions src/lib/fmt/format.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ func (f *Fmt) init() {
}

export func New() *Fmt {
f := new(*Fmt);
f := new(Fmt);
f.init();
return f;
}
Expand Down Expand Up @@ -135,7 +135,7 @@ func (f *Fmt) pad(s string) {
if w > NByte {
w = NByte;
}
buf := new([]byte, w);
buf := make([]byte, w);
for i := 0; i < w; i++ {
buf[i] = padchar;
}
Expand Down
4 changes: 2 additions & 2 deletions src/lib/fmt/print.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ type P struct {
}

func Printer() *P {
p := new(*P);
p := new(P);
p.fmt = fmt.New();
return p;
}
Expand Down Expand Up @@ -81,7 +81,7 @@ func (p *P) ensure(n int) {
if newn < n {
newn = n + AllocSize
}
b := new([]byte, newn);
b := make([]byte, newn);
for i := 0; i < p.n; i++ {
b[i] = p.buf[i];
}
Expand Down
2 changes: 1 addition & 1 deletion src/lib/hash/adler32.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ func (d *Digest) Sum32() uint32 {
}

func (d *Digest) Sum() []byte {
p := new([]byte, 4);
p := make([]byte, 4);
s := d.Sum32();
p[0] = byte(s>>24);
p[1] = byte(s>>16);
Expand Down
4 changes: 2 additions & 2 deletions src/lib/hash/crc32.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ export const (
export type Table []uint32

export func MakeTable(poly uint32) Table {
t := new(Table, 256);
t := make(Table, 256);
for i := 0; i < 256; i++ {
crc := uint32(i);
for j := 0; j < 8; j++ {
Expand Down Expand Up @@ -74,7 +74,7 @@ func (d *Digest) Sum32() uint32 {
}

func (d *Digest) Sum() []byte {
p := new([]byte, 4);
p := make([]byte, 4);
s := d.Sum32();
p[0] = byte(s>>24);
p[1] = byte(s>>16);
Expand Down
4 changes: 2 additions & 2 deletions src/lib/hash/md5.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ export type Digest struct {
}

export func NewDigest() *Digest {
d := new(*Digest);
d := new(Digest);
d.s[0] = A;
d.s[1] = B;
d.s[2] = C;
Expand Down Expand Up @@ -88,7 +88,7 @@ func (d *Digest) Sum() []byte {
panicln("oops");
}

p := new([]byte, 16);
p := make([]byte, 16);
j := 0;
for i := 0; i < 4; i++ {
s := d.s[i];
Expand Down
4 changes: 2 additions & 2 deletions src/lib/hash/sha1.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ export type Digest struct {
}

export func NewDigest() *Digest {
d := new(*Digest);
d := new(Digest);
d.h[0] = H0;
d.h[1] = H1;
d.h[2] = H2;
Expand Down Expand Up @@ -90,7 +90,7 @@ func (d *Digest) Sum() []byte {
panicln("oops");
}

p := new([]byte, 20);
p := make([]byte, 20);
j := 0;
for i := 0; i < 5; i++ {
s := d.h[i];
Expand Down
2 changes: 1 addition & 1 deletion src/lib/http/conn.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ export type Conn struct {

// Create new connection from rwc.
export func NewConn(rwc io.ReadWriteClose) (c *Conn, err *os.Error) {
c = new(*Conn);
c = new(Conn);
c.rwc = rwc;
if c.br, err = bufio.NewBufRead(rwc); err != nil {
return nil, err
Expand Down
Loading

0 comments on commit 5564504

Please sign in to comment.