213
213
//! metadata::locator or metadata::creader for all the juicy details!
214
214
215
215
use std:: borrow:: Cow ;
216
- use std:: io:: { Read , Result as IoResult , Write } ;
216
+ use std:: io:: { Result as IoResult , Write } ;
217
217
use std:: ops:: Deref ;
218
218
use std:: path:: { Path , PathBuf } ;
219
219
use std:: { cmp, fmt} ;
@@ -232,7 +232,6 @@ use rustc_session::utils::CanonicalizedPath;
232
232
use rustc_span:: Span ;
233
233
use rustc_span:: symbol:: Symbol ;
234
234
use rustc_target:: spec:: { Target , TargetTriple } ;
235
- use snap:: read:: FrameDecoder ;
236
235
use tracing:: { debug, info} ;
237
236
238
237
use crate :: creader:: { Library , MetadataLoader } ;
@@ -792,7 +791,6 @@ fn get_metadata_section<'p>(
792
791
CrateFlavor :: Dylib => {
793
792
let buf =
794
793
loader. get_dylib_metadata ( target, filename) . map_err ( MetadataError :: LoadFailure ) ?;
795
- // The header is uncompressed
796
794
let header_len = METADATA_HEADER . len ( ) ;
797
795
// header + u64 length of data
798
796
let data_start = header_len + 8 ;
@@ -806,37 +804,18 @@ fn get_metadata_section<'p>(
806
804
) ) ) ;
807
805
}
808
806
809
- // Length of the compressed stream - this allows linkers to pad the section if they want
807
+ // Length of the metadata - this allows linkers to pad the section if they want
810
808
let Ok ( len_bytes) =
811
809
<[ u8 ; 8 ] >:: try_from ( & buf[ header_len..cmp:: min ( data_start, buf. len ( ) ) ] )
812
810
else {
813
811
return Err ( MetadataError :: LoadFailure (
814
812
"invalid metadata length found" . to_string ( ) ,
815
813
) ) ;
816
814
} ;
817
- let compressed_len = u64:: from_le_bytes ( len_bytes) as usize ;
815
+ let metadata_len = u64:: from_le_bytes ( len_bytes) as usize ;
818
816
819
817
// Header is okay -> inflate the actual metadata
820
- let compressed_bytes = buf. slice ( |buf| & buf[ data_start..( data_start + compressed_len) ] ) ;
821
- if & compressed_bytes[ ..cmp:: min ( METADATA_HEADER . len ( ) , compressed_bytes. len ( ) ) ]
822
- == METADATA_HEADER
823
- {
824
- // The metadata was not actually compressed.
825
- compressed_bytes
826
- } else {
827
- debug ! ( "inflating {} bytes of compressed metadata" , compressed_bytes. len( ) ) ;
828
- // Assume the decompressed data will be at least the size of the compressed data, so we
829
- // don't have to grow the buffer as much.
830
- let mut inflated = Vec :: with_capacity ( compressed_bytes. len ( ) ) ;
831
- FrameDecoder :: new ( & * compressed_bytes) . read_to_end ( & mut inflated) . map_err ( |_| {
832
- MetadataError :: LoadFailure ( format ! (
833
- "failed to decompress metadata: {}" ,
834
- filename. display( )
835
- ) )
836
- } ) ?;
837
-
838
- slice_owned ( inflated, Deref :: deref)
839
- }
818
+ buf. slice ( |buf| & buf[ data_start..( data_start + metadata_len) ] )
840
819
}
841
820
CrateFlavor :: Rmeta => {
842
821
// mmap the file, because only a small fraction of it is read.
0 commit comments