@@ -18,8 +18,8 @@ use crate::generation::SymbolMapGeneration;
1818use crate :: source_file_path:: SourceFilePathHandle ;
1919use crate :: symbol_map:: { GetInnerSymbolMap , SymbolMapTrait } ;
2020use crate :: {
21- Error , FileContents , FileContentsWrapper , FrameDebugInfo , FramesLookupResult , LookupAddress ,
22- SourceFilePath , SymbolInfo , SyncAddressInfo ,
21+ AccessPatternHint , Error , FileContents , FileContentsWrapper , FrameDebugInfo ,
22+ FramesLookupResult , LookupAddress , SourceFilePath , SymbolInfo , SyncAddressInfo ,
2323} ;
2424
2525pub fn get_symbol_map_for_breakpad_sym < FC : FileContents + ' static > (
@@ -138,6 +138,7 @@ struct BreakpadSymbolMapSymbolCache<'a> {
138138 func_symbols : HashMap < u64 , BreakpadFuncSymbolInfo < ' a > > ,
139139 lines : Vec < SourceLine > ,
140140 inlinees : Vec < Inlinee > ,
141+ only_store_latest : bool ,
141142}
142143
143144impl < ' a , T : FileContents > BreakpadSymbolMapCache < ' a , T > {
@@ -151,24 +152,27 @@ impl<'a, T: FileContents> BreakpadSymbolMapCache<'a, T> {
151152}
152153
153154impl < ' a > BreakpadSymbolMapSymbolCache < ' a > {
154- pub fn get_public_info < ' s , T : FileContents > (
155- & ' s mut self ,
155+ pub fn get_public_info < T : FileContents > (
156+ & mut self ,
156157 file_offset : u64 ,
157158 line_length : u32 ,
158159 data : & ' a FileContentsWrapper < T > ,
159- ) -> Result < & ' s BreakpadPublicSymbolInfo < ' a > , Error > {
160- match self . public_symbols . entry ( file_offset) {
161- Entry :: Occupied ( info) => Ok ( info. into_mut ( ) ) ,
162- Entry :: Vacant ( vacant) => {
163- let line = data
164- . read_bytes_at ( file_offset, line_length. into ( ) )
165- . map_err ( |e| {
166- Error :: HelperErrorDuringFileReading ( "Breakpad PUBLIC symbol" . to_string ( ) , e)
167- } ) ?;
168- let info = BreakpadPublicSymbol :: parse ( line) ?;
169- Ok ( vacant. insert ( info) )
170- }
160+ ) -> Result < BreakpadPublicSymbolInfo < ' a > , Error > {
161+ if let Some ( info) = self . public_symbols . get ( & file_offset) {
162+ return Ok ( * info) ;
171163 }
164+
165+ self . clear_if_saving_memory ( ) ;
166+
167+ let line = data
168+ . read_bytes_at ( file_offset, line_length. into ( ) )
169+ . map_err ( |e| {
170+ Error :: HelperErrorDuringFileReading ( "Breakpad PUBLIC symbol" . to_string ( ) , e)
171+ } ) ?;
172+ let info = BreakpadPublicSymbol :: parse ( line) ?;
173+ self . public_symbols . insert ( file_offset, info) ;
174+
175+ Ok ( info)
172176 }
173177
174178 pub fn get_func_info < ' s , T : FileContents > (
@@ -177,17 +181,28 @@ impl<'a> BreakpadSymbolMapSymbolCache<'a> {
177181 block_length : u32 ,
178182 data : & ' a FileContentsWrapper < T > ,
179183 ) -> Result < BreakpadFuncSymbolInfo < ' a > , Error > {
180- match self . func_symbols . entry ( file_offset) {
181- Entry :: Occupied ( info) => Ok ( * info. get ( ) ) ,
182- Entry :: Vacant ( vacant) => {
183- let block = data
184- . read_bytes_at ( file_offset, block_length. into ( ) )
185- . map_err ( |e| {
186- Error :: HelperErrorDuringFileReading ( "Breakpad FUNC symbol" . to_string ( ) , e)
187- } ) ?;
188- let info = BreakpadFuncSymbol :: parse ( block, & mut self . lines , & mut self . inlinees ) ?;
189- Ok ( * vacant. insert ( info) )
190- }
184+ if let Some ( info) = self . func_symbols . get ( & file_offset) {
185+ return Ok ( * info) ;
186+ }
187+
188+ self . clear_if_saving_memory ( ) ;
189+
190+ let block = data
191+ . read_bytes_at ( file_offset, block_length. into ( ) )
192+ . map_err ( |e| {
193+ Error :: HelperErrorDuringFileReading ( "Breakpad FUNC symbol" . to_string ( ) , e)
194+ } ) ?;
195+ let info = BreakpadFuncSymbol :: parse ( block, & mut self . lines , & mut self . inlinees ) ?;
196+ self . func_symbols . insert ( file_offset, info) ;
197+ Ok ( info)
198+ }
199+
200+ fn clear_if_saving_memory ( & mut self ) {
201+ if self . only_store_latest {
202+ self . public_symbols . clear ( ) ;
203+ self . func_symbols . clear ( ) ;
204+ self . inlinees . clear ( ) ;
205+ self . lines . clear ( ) ;
191206 }
192207 }
193208}
@@ -385,6 +400,11 @@ impl<'object, T: FileContents> SymbolMapTrait for BreakpadSymbolMapInner<'object
385400 let s = cache. files . get_string ( index. 0 ) . ok ( ) . unwrap_or ( "<missing>" ) ;
386401 SourceFilePath :: BreakpadSpecialPathStr ( Cow :: Borrowed ( s) )
387402 }
403+
404+ fn set_access_pattern_hint ( & self , hint : AccessPatternHint ) {
405+ let mut cache = self . cache . lock ( ) . unwrap ( ) ;
406+ cache. symbols . only_store_latest = hint == AccessPatternHint :: SequentialLookup ;
407+ }
388408}
389409
390410#[ cfg( test) ]
0 commit comments