Skip to content

Commit 06ef9cb

Browse files
committed
refactor: extract getRawColumns function
1 parent 2224acd commit 06ef9cb

File tree

1 file changed

+19
-35
lines changed
  • packages/vscode-js-profile-flame/src/client/heap

1 file changed

+19
-35
lines changed

packages/vscode-js-profile-flame/src/client/heap/stacks.tsx

+19-35
Original file line numberDiff line numberDiff line change
@@ -92,21 +92,13 @@ export class TreeNodeAccessor implements IHeapProfileNode {
9292
}
9393
}
9494

95-
export const buildLeftHeavyColumns = (model: IProfileModel): IColumn[] => {
96-
const tree = createTree(model);
97-
98-
const columns: IColumn[] = [];
99-
100-
let graphIdCounter = 0;
95+
const getRawColumns = (tree: ITreeNode) => {
10196
const cols: ITreeNode[] = [];
10297

10398
const getCols = (node: ITreeNode) => {
104-
for (const key in node.children) {
105-
if (Object.prototype.hasOwnProperty.call(node.children, key)) {
106-
const child = node.children[key];
107-
getCols(child);
108-
}
109-
}
99+
Object.values(node.children).forEach(child => {
100+
getCols(child);
101+
});
110102

111103
if (node.selfSize) {
112104
cols.push(node);
@@ -115,11 +107,20 @@ export const buildLeftHeavyColumns = (model: IProfileModel): IColumn[] => {
115107

116108
getCols(tree);
117109

118-
cols.sort((a, b) => b.selfSize - a.selfSize);
110+
return cols;
111+
};
112+
113+
export const buildLeftHeavyColumns = (model: IProfileModel): IColumn[] => {
114+
const tree = createTree(model);
115+
const rawColumns = getRawColumns(tree);
116+
const columns: IColumn[] = [];
117+
118+
rawColumns.sort((a, b) => b.selfSize - a.selfSize);
119119

120+
let graphIdCounter = 0;
120121
let sizeOffset = 0;
121-
for (let i = 0; i < cols.length; i++) {
122-
const root = cols[i];
122+
123+
for (const root of rawColumns) {
123124
const rows = [
124125
{
125126
...root,
@@ -160,30 +161,13 @@ export const buildLeftHeavyColumns = (model: IProfileModel): IColumn[] => {
160161
*/
161162
export const buildColumns = (model: IProfileModel) => {
162163
const tree = createTree(model);
163-
164+
const rawColumns = getRawColumns(tree);
164165
const columns: IColumn[] = [];
165166

166167
let graphIdCounter = 0;
167-
const cols: ITreeNode[] = [];
168-
169-
const getCols = (node: ITreeNode) => {
170-
for (const key in node.children) {
171-
if (Object.prototype.hasOwnProperty.call(node.children, key)) {
172-
const child = node.children[key];
173-
getCols(child);
174-
}
175-
}
176-
177-
if (node.selfSize) {
178-
cols.push(node);
179-
}
180-
};
181-
182-
getCols(tree);
183-
184168
let sizeOffset = 0;
185-
for (let i = 0; i < cols.length; i++) {
186-
const root = cols[i];
169+
170+
for (const root of rawColumns) {
187171
const rows = [];
188172

189173
for (let node: ITreeNode | undefined = root; node; node = node.parent) {

0 commit comments

Comments
 (0)