From ffbf5a7f28058787dc6476ad436b550412fce981 Mon Sep 17 00:00:00 2001 From: Benjamin Christopher Simmonds <44439583+benibenj@users.noreply.github.com> Date: Thu, 19 Dec 2024 16:51:06 +0100 Subject: [PATCH] Use indices for queue processing instead of Array.shift() (#236601) * Use indices instead of Array.shift() * :lipstick: --- src/vs/base/browser/ui/tree/abstractTree.ts | 8 ++++---- src/vs/base/browser/ui/tree/asyncDataTree.ts | 4 ++-- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/vs/base/browser/ui/tree/abstractTree.ts b/src/vs/base/browser/ui/tree/abstractTree.ts index b8144e58c23..09ce418bda9 100644 --- a/src/vs/base/browser/ui/tree/abstractTree.ts +++ b/src/vs/base/browser/ui/tree/abstractTree.ts @@ -3080,16 +3080,16 @@ export abstract class AbstractTree implements IDisposable } const root = this.model.getNode(); - const queue = [root]; + const stack = [root]; - while (queue.length > 0) { - const node = queue.shift()!; + while (stack.length > 0) { + const node = stack.pop()!; if (node !== root && node.collapsible) { state.expanded[getId(node.element)] = node.collapsed ? 0 : 1; } - insertInto(queue, queue.length, node.children); + insertInto(stack, stack.length, node.children); } return state; diff --git a/src/vs/base/browser/ui/tree/asyncDataTree.ts b/src/vs/base/browser/ui/tree/asyncDataTree.ts index 9d0d2cbf4b2..dd6059051f0 100644 --- a/src/vs/base/browser/ui/tree/asyncDataTree.ts +++ b/src/vs/base/browser/ui/tree/asyncDataTree.ts @@ -24,7 +24,7 @@ import { isIterable } from '../../../common/types.js'; import { CancellationToken, CancellationTokenSource } from '../../../common/cancellation.js'; import { IContextViewProvider } from '../contextview/contextview.js'; import { FuzzyScore } from '../../../common/filters.js'; -import { splice } from '../../../common/arrays.js'; +import { insertInto, splice } from '../../../common/arrays.js'; import { localize } from '../../../../nls.js'; interface IAsyncDataTreeNode { @@ -1350,7 +1350,7 @@ export class AsyncDataTree implements IDisposable expanded.push(getId(node.element!.element as T)); } - stack.push(...node.children); + insertInto(stack, stack.length, node.children); } return { focus, selection, expanded, scrollTop: this.scrollTop };