Skip to content
This repository has been archived by the owner on May 21, 2019. It is now read-only.

Commit

Permalink
Improved performance of PaneList next & previous methods (#1002)
Browse files Browse the repository at this point in the history
  • Loading branch information
mkenne11 authored and drew-gross committed Mar 27, 2017
1 parent 35901cc commit e835f3a
Showing 1 changed file with 18 additions and 32 deletions.
50 changes: 18 additions & 32 deletions src/utils/PaneTree.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,28 +83,21 @@ export abstract class PaneList {
* @returns {Pane}
*/
previous(pane: Pane): Pane {
const firstPaneIndex = 0;
const lastPaneIndex = this.size - 1;
let paneIndex = 0;
let panes: Pane[] = [];

this.forEach((current, index) => {
if (pane === current) {
this.forEach((currentPane, index) => {
panes.push(currentPane);
if (pane === currentPane) {
paneIndex = index;
}
});

let previous = pane;

this.forEach((current, index) => {
if (paneIndex === firstPaneIndex) {
if (index === lastPaneIndex)
previous = current;
} else if (index === paneIndex - 1) {
previous = current;
}
});

return previous;
if (paneIndex === 0) {
return panes[panes.length - 1];
} else {
return panes[paneIndex - 1];
}
}

/**
Expand All @@ -113,28 +106,21 @@ export abstract class PaneList {
* @returns {Pane}
*/
next(pane: Pane): Pane {
const firstPaneIndex = 0;
const lastPaneIndex = this.size - 1;
let paneIndex = 0;
let panes: Pane[] = [];

this.forEach((current, index) => {
if (pane === current) {
this.forEach((currentPane, index) => {
panes.push(currentPane);
if (pane === currentPane) {
paneIndex = index;
}
});

let next = pane;

this.forEach((current, index) => {
if (paneIndex === lastPaneIndex) {
if (index === firstPaneIndex)
next = current;
} else if (index === paneIndex + 1) {
next = current;
}
});

return next;
if (paneIndex === panes.length - 1) {
return panes[0];
} else {
return panes[paneIndex + 1];
}
}

protected abstract insertBelow(position: number, pane: Pane): void;
Expand Down

0 comments on commit e835f3a

Please sign in to comment.