@@ -25,7 +25,7 @@ import {
2525} from 'firefox-profiler/app-logic/constants' ;
2626import { timeCode } from 'firefox-profiler/utils/time-code' ;
2727import { 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' ;
2929import { parseFileNameFromSymbolication } from 'firefox-profiler/utils/special-paths' ;
3030import { StringTable } from 'firefox-profiler/utils/string-table' ;
3131import {
@@ -1504,7 +1504,7 @@ export function filterThreadToSearchString(
15041504 const { funcTable, frameTable, stackTable, stringTable, resourceTable } =
15051505 thread ;
15061506
1507- function computeFuncMatchesFilter ( func : IndexIntoFuncTable ) {
1507+ function computeFuncMatchesSearch ( func : IndexIntoFuncTable ) {
15081508 const nameIndex = funcTable . name [ func ] ;
15091509 const nameString = stringTable . getString ( nameIndex ) ;
15101510 if ( nameString . toLowerCase ( ) . includes ( lowercaseSearchString ) ) {
@@ -1531,38 +1531,32 @@ export function filterThreadToSearchString(
15311531 return false ;
15321532 }
15331533
1534- const funcMatchesFilterCache = new Map ( ) ;
1535- function funcMatchesFilter ( func : IndexIntoFuncTable ) {
1536- let result = funcMatchesFilterCache . get ( func ) ;
1537- if ( result === undefined ) {
1538- result = computeFuncMatchesFilter ( func ) ;
1539- funcMatchesFilterCache . set ( func , result ) ;
1534+ const funcMatchesSearch = makeBitSet ( funcTable . length ) ;
1535+ for ( let funcIndex = 0 ; funcIndex < funcTable . length ; funcIndex ++ ) {
1536+ if ( computeFuncMatchesSearch ( funcIndex ) ) {
1537+ setBit ( funcMatchesSearch , funcIndex ) ;
15401538 }
1541- return result ;
15421539 }
15431540
1544- const stackMatchesFilterCache = new Map ( ) ;
1545- function stackMatchesFilter ( stackIndex : IndexIntoStackTable | null ) {
1546- if ( stackIndex === null ) {
1547- return false ;
1548- }
1549- let result = stackMatchesFilterCache . get ( stackIndex ) ;
1550- if ( result === undefined ) {
1551- const prefix = stackTable . prefix [ stackIndex ] ;
1552- if ( stackMatchesFilter ( prefix ) ) {
1553- result = true ;
1554- } else {
1555- const frame = stackTable . frame [ stackIndex ] ;
1556- const func = frameTable . func [ frame ] ;
1557- result = funcMatchesFilter ( func ) ;
1541+ const stackMatchesSearch = makeBitSet ( funcTable . length ) ;
1542+ for ( let stackIndex = 0 ; stackIndex < stackTable . length ; stackIndex ++ ) {
1543+ const prefix = stackTable . prefix [ stackIndex ] ;
1544+ if ( prefix !== null && checkBit ( stackMatchesSearch , prefix ) ) {
1545+ setBit ( stackMatchesSearch , stackIndex ) ;
1546+ } else {
1547+ const funcIndex = frameTable . func [ stackTable . frame [ stackIndex ] ] ;
1548+ if ( checkBit ( funcMatchesSearch , funcIndex ) ) {
1549+ setBit ( stackMatchesSearch , stackIndex ) ;
15581550 }
1559- stackMatchesFilterCache . set ( stackIndex , result ) ;
15601551 }
1561- return result ;
15621552 }
15631553
1554+ // Set any stacks which don't include the search string to null.
1555+ // TODO: This includes stacks in markers; maybe we shouldn't clear marker stacks?
15641556 return updateThreadStacks ( thread , stackTable , ( stackIndex ) =>
1565- stackMatchesFilter ( stackIndex ) ? stackIndex : null
1557+ stackIndex !== null && checkBit ( stackMatchesSearch , stackIndex )
1558+ ? stackIndex
1559+ : null
15661560 ) ;
15671561}
15681562
0 commit comments