Skip to content

Update handlecache.ts (#24233) #24256

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 4, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 6 additions & 8 deletions packages/dds/matrix/src/handlecache.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,11 +72,10 @@ export class HandleCache implements IVectorConsumer<Handle> {
/**
* 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++) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd think we want to remove return handles; statement at the bottom, as not used / useful?

Expand All @@ -102,16 +101,15 @@ export class HandleCache implements IVectorConsumer<Handle> {
// 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];
}
}
Expand Down
Loading