mirror of
https://github.com/golang/go
synced 2024-11-22 08:04:39 -07:00
vector: use correct capacity in call to make
R=gri, r, bflm CC=golang-dev https://golang.org/cl/1032043
This commit is contained in:
parent
58e77990ba
commit
cf0e224380
@ -12,6 +12,9 @@ func (p *IntVector) realloc(length, capacity int) (b []int) {
|
|||||||
if capacity < initialSize {
|
if capacity < initialSize {
|
||||||
capacity = initialSize
|
capacity = initialSize
|
||||||
}
|
}
|
||||||
|
if capacity < length {
|
||||||
|
capacity = length
|
||||||
|
}
|
||||||
b = make(IntVector, length, capacity)
|
b = make(IntVector, length, capacity)
|
||||||
copy(b, *p)
|
copy(b, *p)
|
||||||
*p = b
|
*p = b
|
||||||
@ -186,9 +189,7 @@ func (p *IntVector) Pop() int {
|
|||||||
|
|
||||||
|
|
||||||
// AppendVector appends the entire vector x to the end of this vector.
|
// AppendVector appends the entire vector x to the end of this vector.
|
||||||
func (p *IntVector) AppendVector(x *IntVector) {
|
func (p *IntVector) AppendVector(x *IntVector) { p.InsertVector(len(*p), x) }
|
||||||
p.InsertVector(len(*p), x)
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
// Swap exchanges the elements at indexes i and j.
|
// Swap exchanges the elements at indexes i and j.
|
||||||
|
@ -12,6 +12,9 @@ func (p *StringVector) realloc(length, capacity int) (b []string) {
|
|||||||
if capacity < initialSize {
|
if capacity < initialSize {
|
||||||
capacity = initialSize
|
capacity = initialSize
|
||||||
}
|
}
|
||||||
|
if capacity < length {
|
||||||
|
capacity = length
|
||||||
|
}
|
||||||
b = make(StringVector, length, capacity)
|
b = make(StringVector, length, capacity)
|
||||||
copy(b, *p)
|
copy(b, *p)
|
||||||
*p = b
|
*p = b
|
||||||
@ -186,9 +189,7 @@ func (p *StringVector) Pop() string {
|
|||||||
|
|
||||||
|
|
||||||
// AppendVector appends the entire vector x to the end of this vector.
|
// AppendVector appends the entire vector x to the end of this vector.
|
||||||
func (p *StringVector) AppendVector(x *StringVector) {
|
func (p *StringVector) AppendVector(x *StringVector) { p.InsertVector(len(*p), x) }
|
||||||
p.InsertVector(len(*p), x)
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
// Swap exchanges the elements at indexes i and j.
|
// Swap exchanges the elements at indexes i and j.
|
||||||
|
@ -12,6 +12,9 @@ func (p *Vector) realloc(length, capacity int) (b []interface{}) {
|
|||||||
if capacity < initialSize {
|
if capacity < initialSize {
|
||||||
capacity = initialSize
|
capacity = initialSize
|
||||||
}
|
}
|
||||||
|
if capacity < length {
|
||||||
|
capacity = length
|
||||||
|
}
|
||||||
b = make(Vector, length, capacity)
|
b = make(Vector, length, capacity)
|
||||||
copy(b, *p)
|
copy(b, *p)
|
||||||
*p = b
|
*p = b
|
||||||
|
Loading…
Reference in New Issue
Block a user