]> Cypherpunks repositories - gostls13.git/commitdiff
vector: use correct capacity in call to make
authorRuss Cox <rsc@golang.org>
Sat, 1 May 2010 20:00:01 +0000 (13:00 -0700)
committerRuss Cox <rsc@golang.org>
Sat, 1 May 2010 20:00:01 +0000 (13:00 -0700)
R=gri, r, bflm
CC=golang-dev
https://golang.org/cl/1032043

src/pkg/container/vector/intvector.go
src/pkg/container/vector/stringvector.go
src/pkg/container/vector/vector.go

index a1754a94f1d470067258edbbbcb12408609841a5..708108b183948010f979572d9d7fadff21629562 100644 (file)
@@ -12,6 +12,9 @@ func (p *IntVector) realloc(length, capacity int) (b []int) {
        if capacity < initialSize {
                capacity = initialSize
        }
+       if capacity < length {
+               capacity = length
+       }
        b = make(IntVector, length, capacity)
        copy(b, *p)
        *p = b
@@ -186,9 +189,7 @@ func (p *IntVector) Pop() int {
 
 
 // AppendVector appends the entire vector x to the end of this vector.
-func (p *IntVector) AppendVector(x *IntVector) {
-       p.InsertVector(len(*p), x)
-}
+func (p *IntVector) AppendVector(x *IntVector) { p.InsertVector(len(*p), x) }
 
 
 // Swap exchanges the elements at indexes i and j.
index fad20f58a54c850613b014912d19a060631fd1a0..86563ca2034776f68df978de729d0dbab09ca3d6 100644 (file)
@@ -12,6 +12,9 @@ func (p *StringVector) realloc(length, capacity int) (b []string) {
        if capacity < initialSize {
                capacity = initialSize
        }
+       if capacity < length {
+               capacity = length
+       }
        b = make(StringVector, length, capacity)
        copy(b, *p)
        *p = b
@@ -186,9 +189,7 @@ func (p *StringVector) Pop() string {
 
 
 // AppendVector appends the entire vector x to the end of this vector.
-func (p *StringVector) AppendVector(x *StringVector) {
-       p.InsertVector(len(*p), x)
-}
+func (p *StringVector) AppendVector(x *StringVector) { p.InsertVector(len(*p), x) }
 
 
 // Swap exchanges the elements at indexes i and j.
index 99c7753da3d7e6628c714202d891972852dd3aeb..0771720965435957faa9330a85633ea3edce295b 100644 (file)
@@ -12,6 +12,9 @@ func (p *Vector) realloc(length, capacity int) (b []interface{}) {
        if capacity < initialSize {
                capacity = initialSize
        }
+       if capacity < length {
+               capacity = length
+       }
        b = make(Vector, length, capacity)
        copy(b, *p)
        *p = b