@@ -3,17 +3,18 @@ use std::sync::Arc;
3
3
4
4
use serde:: ser:: { Serialize , Serializer } ;
5
5
6
- use crate :: fast_hash_map:: FastHashMap ;
6
+ use crate :: fast_hash_map:: { FastHashMap , FastIndexSet } ;
7
7
use crate :: { LibraryInfo , SymbolTable } ;
8
8
9
9
#[ derive( Debug ) ]
10
10
pub struct GlobalLibTable {
11
- /// All libraries added via `Profile::add_lib `. May or may not be used.
11
+ /// All libraries added via `Profile::handle_for_lib `. May or may not be used.
12
12
/// Indexed by `LibraryHandle.0`.
13
- all_libs : Vec < LibraryInfo > , // append-only for stable LibraryHandles
13
+ all_libs : FastIndexSet < LibraryInfo > , // append-only for stable LibraryHandles
14
+ /// Any symbol tables for libraries in all_libs
15
+ symbol_tables : FastHashMap < LibraryHandle , Arc < SymbolTable > > ,
14
16
/// Indexed by `GlobalLibIndex.0`.
15
17
used_libs : Vec < LibraryHandle > , // append-only for stable GlobalLibIndexes
16
- lib_map : FastHashMap < LibraryInfo , LibraryHandle > ,
17
18
used_lib_map : FastHashMap < LibraryHandle , GlobalLibIndex > ,
18
19
/// We keep track of RVA addresses that exist in frames that are assigned to this
19
20
/// library, so that we can potentially provide symbolication info ahead of time.
@@ -26,25 +27,20 @@ pub struct GlobalLibTable {
26
27
impl GlobalLibTable {
27
28
pub fn new ( ) -> Self {
28
29
Self {
29
- all_libs : Vec :: new ( ) ,
30
+ all_libs : FastIndexSet :: default ( ) ,
31
+ symbol_tables : FastHashMap :: default ( ) ,
30
32
used_libs : Vec :: new ( ) ,
31
- lib_map : FastHashMap :: default ( ) ,
32
33
used_lib_map : FastHashMap :: default ( ) ,
33
34
used_libs_seen_rvas : Vec :: new ( ) ,
34
35
}
35
36
}
36
37
37
38
pub fn handle_for_lib ( & mut self , lib : LibraryInfo ) -> LibraryHandle {
38
- let all_libs = & mut self . all_libs ;
39
- * self . lib_map . entry ( lib. clone ( ) ) . or_insert_with ( || {
40
- let handle = LibraryHandle ( all_libs. len ( ) ) ;
41
- all_libs. push ( lib) ;
42
- handle
43
- } )
39
+ LibraryHandle ( self . all_libs . insert_full ( lib) . 0 )
44
40
}
45
41
46
42
pub fn set_lib_symbol_table ( & mut self , library : LibraryHandle , symbol_table : Arc < SymbolTable > ) {
47
- self . all_libs [ library . 0 ] . symbol_table = Some ( symbol_table) ;
43
+ self . symbol_tables . insert ( library , symbol_table) ;
48
44
}
49
45
50
46
pub fn index_for_used_lib ( & mut self , lib_handle : LibraryHandle ) -> GlobalLibIndex {
@@ -59,7 +55,12 @@ impl GlobalLibTable {
59
55
60
56
pub fn get_lib ( & self , index : GlobalLibIndex ) -> Option < & LibraryInfo > {
61
57
let handle = self . used_libs . get ( index. 0 ) ?;
62
- self . all_libs . get ( handle. 0 )
58
+ self . all_libs . get_index ( handle. 0 )
59
+ }
60
+
61
+ pub fn get_lib_symbol_table ( & self , index : GlobalLibIndex ) -> Option < & SymbolTable > {
62
+ let handle = self . used_libs . get ( index. 0 ) ?;
63
+ self . symbol_tables . get ( handle) . map ( |v| & * * v)
63
64
}
64
65
65
66
pub fn add_lib_used_rva ( & mut self , index : GlobalLibIndex , address : u32 ) {
0 commit comments