Skip to content

Commit a4d4363

Browse files
committed
Remove recursion in filterThreadToSearchString.
1 parent 7e3388c commit a4d4363

File tree

1 file changed

+20
-26
lines changed

1 file changed

+20
-26
lines changed

src/profile-logic/profile-data.ts

Lines changed: 20 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ import {
2525
} from 'firefox-profiler/app-logic/constants';
2626
import { timeCode } from 'firefox-profiler/utils/time-code';
2727
import { bisectionRight, bisectionLeft } from 'firefox-profiler/utils/bisect';
28-
import { makeBitSet } from 'firefox-profiler/utils/bitset';
28+
import { checkBit, makeBitSet, setBit } from 'firefox-profiler/utils/bitset';
2929
import { parseFileNameFromSymbolication } from 'firefox-profiler/utils/special-paths';
3030
import { StringTable } from 'firefox-profiler/utils/string-table';
3131
import {
@@ -1507,7 +1507,7 @@ export function filterThreadToSearchString(
15071507
const { funcTable, frameTable, stackTable, stringTable, resourceTable } =
15081508
thread;
15091509

1510-
function computeFuncMatchesFilter(func: IndexIntoFuncTable) {
1510+
function computeFuncMatchesSearch(func: IndexIntoFuncTable) {
15111511
const nameIndex = funcTable.name[func];
15121512
const nameString = stringTable.getString(nameIndex);
15131513
if (nameString.toLowerCase().includes(lowercaseSearchString)) {
@@ -1534,38 +1534,32 @@ export function filterThreadToSearchString(
15341534
return false;
15351535
}
15361536

1537-
const funcMatchesFilterCache = new Map();
1538-
function funcMatchesFilter(func: IndexIntoFuncTable) {
1539-
let result = funcMatchesFilterCache.get(func);
1540-
if (result === undefined) {
1541-
result = computeFuncMatchesFilter(func);
1542-
funcMatchesFilterCache.set(func, result);
1537+
const funcMatchesSearch = makeBitSet(funcTable.length);
1538+
for (let funcIndex = 0; funcIndex < funcTable.length; funcIndex++) {
1539+
if (computeFuncMatchesSearch(funcIndex)) {
1540+
setBit(funcMatchesSearch, funcIndex);
15431541
}
1544-
return result;
15451542
}
15461543

1547-
const stackMatchesFilterCache = new Map();
1548-
function stackMatchesFilter(stackIndex: IndexIntoStackTable | null) {
1549-
if (stackIndex === null) {
1550-
return false;
1551-
}
1552-
let result = stackMatchesFilterCache.get(stackIndex);
1553-
if (result === undefined) {
1554-
const prefix = stackTable.prefix[stackIndex];
1555-
if (stackMatchesFilter(prefix)) {
1556-
result = true;
1557-
} else {
1558-
const frame = stackTable.frame[stackIndex];
1559-
const func = frameTable.func[frame];
1560-
result = funcMatchesFilter(func);
1544+
const stackMatchesSearch = makeBitSet(funcTable.length);
1545+
for (let stackIndex = 0; stackIndex < stackTable.length; stackIndex++) {
1546+
const prefix = stackTable.prefix[stackIndex];
1547+
if (prefix !== null && checkBit(stackMatchesSearch, prefix)) {
1548+
setBit(stackMatchesSearch, stackIndex);
1549+
} else {
1550+
const funcIndex = frameTable.func[stackTable.frame[stackIndex]];
1551+
if (checkBit(funcMatchesSearch, funcIndex)) {
1552+
setBit(stackMatchesSearch, stackIndex);
15611553
}
1562-
stackMatchesFilterCache.set(stackIndex, result);
15631554
}
1564-
return result;
15651555
}
15661556

1557+
// Set any stacks which don't include the search string to null.
1558+
// TODO: This includes stacks in markers; maybe we shouldn't clear marker stacks?
15671559
return updateThreadStacks(thread, stackTable, (stackIndex) =>
1568-
stackMatchesFilter(stackIndex) ? stackIndex : null
1560+
stackIndex !== null && checkBit(stackMatchesSearch, stackIndex)
1561+
? stackIndex
1562+
: null
15691563
);
15701564
}
15711565

0 commit comments

Comments
 (0)