213213//! metadata::locator or metadata::creader for all the juicy details!
214214
215215use std:: borrow:: Cow ;
216- use std:: io:: { Read , Result as IoResult , Write } ;
216+ use std:: io:: { Result as IoResult , Write } ;
217217use std:: ops:: Deref ;
218218use std:: path:: { Path , PathBuf } ;
219219use std:: { cmp, fmt} ;
@@ -232,7 +232,6 @@ use rustc_session::utils::CanonicalizedPath;
232232use rustc_span:: Span ;
233233use rustc_span:: symbol:: Symbol ;
234234use rustc_target:: spec:: { Target , TargetTriple } ;
235- use snap:: read:: FrameDecoder ;
236235use tracing:: { debug, info} ;
237236
238237use crate :: creader:: { Library , MetadataLoader } ;
@@ -792,7 +791,6 @@ fn get_metadata_section<'p>(
792791 CrateFlavor :: Dylib => {
793792 let buf =
794793 loader. get_dylib_metadata ( target, filename) . map_err ( MetadataError :: LoadFailure ) ?;
795- // The header is uncompressed
796794 let header_len = METADATA_HEADER . len ( ) ;
797795 // header + u64 length of data
798796 let data_start = header_len + 8 ;
@@ -806,37 +804,18 @@ fn get_metadata_section<'p>(
806804 ) ) ) ;
807805 }
808806
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
810808 let Ok ( len_bytes) =
811809 <[ u8 ; 8 ] >:: try_from ( & buf[ header_len..cmp:: min ( data_start, buf. len ( ) ) ] )
812810 else {
813811 return Err ( MetadataError :: LoadFailure (
814812 "invalid metadata length found" . to_string ( ) ,
815813 ) ) ;
816814 } ;
817- let compressed_len = u64:: from_le_bytes ( len_bytes) as usize ;
815+ let metadata_len = u64:: from_le_bytes ( len_bytes) as usize ;
818816
819817 // 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) ] )
840819 }
841820 CrateFlavor :: Rmeta => {
842821 // mmap the file, because only a small fraction of it is read.
0 commit comments