* Doubles the capacity of the buffer.
()
| 50 | * Doubles the capacity of the buffer. |
| 51 | */ |
| 52 | private expand() { |
| 53 | const newCapacity = this.capacity * 2; |
| 54 | const newData = new Array<T>(newCapacity); |
| 55 | const len = this.length(); |
| 56 | |
| 57 | // Rotate the buffer to start at index 0 again, since we can't just |
| 58 | // allocate more space at the end. |
| 59 | for (let i = 0; i < len; i++) { |
| 60 | newData[i] = this.get(this.wrap(this.begin + i)); |
| 61 | } |
| 62 | |
| 63 | this.data = newData; |
| 64 | this.capacity = newCapacity; |
| 65 | this.doubledCapacity = 2 * this.capacity; |
| 66 | this.begin = 0; |
| 67 | this.end = len; |
| 68 | } |
| 69 | } |