diff --git a/packages/dds/matrix/src/handlecache.ts b/packages/dds/matrix/src/handlecache.ts index 315985f32bca..66080232c99f 100644 --- a/packages/dds/matrix/src/handlecache.ts +++ b/packages/dds/matrix/src/handlecache.ts @@ -72,11 +72,10 @@ export class HandleCache implements IVectorConsumer { /** * Used by {@link HandleCache.cacheMiss} to retrieve handles for a range of positions. */ - private getHandles(start: number, end: number): Handle[] { + private getHandles(start: number, end: number, handles: Handle[]): Handle[] { // TODO: This can be accelerated substantially using 'walkSegments()'. The only catch // is that - const handles: Handle[] = []; const { vector } = this; for (let pos = start; pos < end; pos++) { @@ -102,16 +101,15 @@ export class HandleCache implements IVectorConsumer { // the handle cache). if (_position < this.start) { - this.handles = [...this.getHandles(_position, this.start), ...this.handles]; + const handles: Handle[] = []; + this.getHandles(_position, this.start, handles); + handles.push(...this.handles); + this.handles = handles; this.start = _position; return this.handles[0]; } else { ensureRange(_position, this.vector.getLength()); - - this.handles = [ - ...this.handles, - ...this.getHandles(this.start + this.handles.length, _position + 1), - ]; + this.getHandles(this.start + this.handles.length, _position + 1, this.handles); return this.handles[this.handles.length - 1]; } }