@@ -2,11 +2,7 @@ import type { DebugImage, StackParser } from '@sentry/types';
2
2
import { GLOBAL_OBJ } from './worldwide' ;
3
3
4
4
type StackString = string ;
5
-
6
- interface CachedResult {
7
- filename : string ;
8
- debugId : string ;
9
- }
5
+ type CachedResult = [ string , string ] ;
10
6
11
7
let debugIdStackParserCache : WeakMap < StackParser , Map < StackString , CachedResult > > | undefined ;
12
8
@@ -25,8 +21,8 @@ function getCacheForStackParser(stackParser: StackParser): Map<StackString, Cach
25
21
return result ;
26
22
}
27
23
28
- let lastDebugIdKeyCount = 0 ;
29
- let cachedFilenameToDebugId : Map < string , string > | undefined ;
24
+ let lastCount = 0 ;
25
+ let cachedFilenameDebugIds : Map < string , string > | undefined ;
30
26
31
27
/**
32
28
* Returns a map of filenames to debug identifiers.
@@ -41,17 +37,19 @@ export function getFilenameToDebugIdMap(stackParser: StackParser): Map<string, s
41
37
42
38
// If the count of registered globals hasn't changed since the last call, we
43
39
// can just return the cached result.
44
- if ( debugIdKeys . length === lastDebugIdKeyCount && cachedFilenameToDebugId ) {
45
- return cachedFilenameToDebugId ;
40
+ if ( cachedFilenameDebugIds && debugIdKeys . length === lastCount ) {
41
+ return cachedFilenameDebugIds ;
46
42
}
47
43
48
44
const debugIdStackFramesCache = getCacheForStackParser ( stackParser ) ;
49
45
50
46
// Build a map of filename -> debug_id.
51
- const output = debugIdKeys . reduce < Map < string , string > > ( ( acc , debugIdStackTrace ) => {
52
- let result = debugIdStackFramesCache . get ( debugIdStackTrace ) ;
47
+ cachedFilenameDebugIds = debugIdKeys . reduce < Map < string , string > > ( ( acc , debugIdStackTrace ) => {
48
+ const result = debugIdStackFramesCache . get ( debugIdStackTrace ) ;
53
49
54
- if ( ! result ) {
50
+ if ( result ) {
51
+ acc . set ( result [ 0 ] , result [ 1 ] ) ;
52
+ } else {
55
53
const parsedStack = stackParser ( debugIdStackTrace ) ;
56
54
57
55
for ( let i = parsedStack . length - 1 ; i >= 0 ; i -- ) {
@@ -60,24 +58,19 @@ export function getFilenameToDebugIdMap(stackParser: StackParser): Map<string, s
60
58
const debugId = debugIdMap [ debugIdStackTrace ] ;
61
59
62
60
if ( filename && debugId ) {
63
- result = { filename, debugId } ;
61
+ acc . set ( filename , debugId ) ;
64
62
debugIdStackFramesCache . set ( debugIdStackTrace , result ) ;
65
63
break ;
66
64
}
67
65
}
68
66
}
69
67
70
- if ( result ) {
71
- acc . set ( result . filename , result . debugId ) ;
72
- }
73
-
74
68
return acc ;
75
69
} , new Map ( ) ) ;
76
70
77
- lastDebugIdKeyCount = Object . keys ( debugIdMap ) . length ;
78
- cachedFilenameToDebugId = output ;
71
+ lastCount = debugIdKeys . length ;
79
72
80
- return output ;
73
+ return cachedFilenameDebugIds ;
81
74
}
82
75
83
76
/**
0 commit comments