@@ -1993,7 +1993,7 @@ export function hasUsefulSamples(
19931993 // All samples were null.
19941994 return false ;
19951995 }
1996- if ( stackTable . prefix [ stackIndex ] === - 1 ) {
1996+ if ( stackTable . prefixOffset [ stackIndex ] === 0 ) {
19971997 // There's only a single stack frame, check if it's '(root)'.
19981998 const frameIndex = stackTable . frame [ stackIndex ] ;
19991999 const funcIndex = frameTable . func [ frameIndex ] ;
@@ -4081,11 +4081,7 @@ export function collectSourceIndicesFromThreads(
40814081
40824082 const addStackChain = ( stackIndex : IndexIntoStackTable | null ) => {
40834083 let current = stackIndex ;
4084- while (
4085- current !== null &&
4086- current !== - 1 &&
4087- ! checkBit ( visitedStacks , current )
4088- ) {
4084+ while ( current !== null && ! checkBit ( visitedStacks , current ) ) {
40894085 setBit ( visitedStacks , current ) ;
40904086 const frameIndex = stackTable . frame [ current ] ;
40914087 const funcIndex = frameTable . func [ frameIndex ] ;
@@ -4105,7 +4101,8 @@ export function collectSourceIndicesFromThreads(
41054101 sourceIndices . add ( sourceLocationTable . source [ funcOriginalLocationIdx ] ) ;
41064102 }
41074103
4108- current = stackTable . prefix [ current ] ;
4104+ const prefixOffset = stackTable . prefixOffset [ current ] ;
4105+ current = prefixOffset !== 0 ? current - prefixOffset : null ;
41094106 }
41104107 } ;
41114108
@@ -4289,8 +4286,12 @@ export function nudgeReturnAddresses(profile: Profile): Profile {
42894286 }
42904287 }
42914288 for ( let stack = 0 ; stack < stackTable . length ; stack ++ ) {
4292- const prefix = stackTable . prefix [ stack ] ;
4293- if ( prefix === - 1 || prefixStacks . has ( prefix ) ) {
4289+ const offset = stackTable . prefixOffset [ stack ] ;
4290+ if ( offset === 0 ) {
4291+ continue ;
4292+ }
4293+ const prefix = stack - offset ;
4294+ if ( prefixStacks . has ( prefix ) ) {
42944295 continue ;
42954296 }
42964297 prefixStacks . add ( prefix ) ;
@@ -4363,7 +4364,8 @@ export function nudgeReturnAddresses(profile: Profile): Profile {
43634364 const prefixMap = new Uint32Array ( stackTable . length ) ;
43644365 for ( let stack = 0 ; stack < stackTable . length ; stack ++ ) {
43654366 const frame = stackTable . frame [ stack ] ;
4366- const prefix = stackTable . prefix [ stack ] ;
4367+ const offset = stackTable . prefixOffset [ stack ] ;
4368+ const prefix = offset === 0 ? - 1 : stack - offset ;
43674369
43684370 const newPrefix = prefix === - 1 ? null : prefixMap [ prefix ] ;
43694371
@@ -4747,7 +4749,12 @@ export function computeStackTableFromRawStackTable(
47474749 maxSubcategoryCount < 256
47484750 ? new Uint8Array ( rawStackTable . length )
47494751 : new Uint16Array ( rawStackTable . length ) ;
4752+ const prefix = new Int32Array ( rawStackTable . length ) ;
47504753 for ( let stackIndex = 0 ; stackIndex < rawStackTable . length ; stackIndex ++ ) {
4754+ const offset = rawStackTable . prefixOffset [ stackIndex ] ;
4755+ const prefixStack = offset === 0 ? - 1 : stackIndex - offset ;
4756+ prefix [ stackIndex ] = prefixStack ;
4757+
47514758 const frameIndex = rawStackTable . frame [ stackIndex ] ;
47524759 const frameCategory = frameTable . category [ frameIndex ] ;
47534760 const frameSubcategory = frameTable . subcategory [ frameIndex ] ;
@@ -4756,17 +4763,14 @@ export function computeStackTableFromRawStackTable(
47564763 if ( frameCategory !== null ) {
47574764 stackCategory = frameCategory ;
47584765 stackSubcategory = frameSubcategory || 0 ;
4766+ } else if ( prefixStack !== - 1 ) {
4767+ // Because of the structure of the stack table, prefix < stackIndex.
4768+ // So we've already computed the category for the prefix.
4769+ stackCategory = categoryColumn [ prefixStack ] ;
4770+ stackSubcategory = subcategoryColumn [ prefixStack ] ;
47594771 } else {
4760- const prefix = rawStackTable . prefix [ stackIndex ] ;
4761- if ( prefix !== - 1 ) {
4762- // Because of the structure of the stack table, prefix < stackIndex.
4763- // So we've already computed the category for the prefix.
4764- stackCategory = categoryColumn [ prefix ] ;
4765- stackSubcategory = subcategoryColumn [ prefix ] ;
4766- } else {
4767- stackCategory = defaultCategory ;
4768- stackSubcategory = 0 ;
4769- }
4772+ stackCategory = defaultCategory ;
4773+ stackSubcategory = 0 ;
47704774 }
47714775 categoryColumn [ stackIndex ] = stackCategory ;
47724776 subcategoryColumn [ stackIndex ] = stackSubcategory ;
@@ -4782,7 +4786,7 @@ export function computeStackTableFromRawStackTable(
47824786 frame,
47834787 category : categoryColumn ,
47844788 subcategory : subcategoryColumn ,
4785- prefix : rawStackTable . prefix ,
4789+ prefix,
47864790 length : rawStackTable . length ,
47874791 } ;
47884792}
0 commit comments