Skip to content

Commit

Permalink
swf: Memcpy the swf header away instead of creating an entire new Vec
Browse files Browse the repository at this point in the history
  • Loading branch information
adrian17 authored and Dinnerbone committed Nov 27, 2024
1 parent 6202d37 commit e9e4ceb
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion swf/src/read.rs
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,12 @@ pub fn decompress_swf<'a, R: Read + 'a>(mut input: R) -> Result<SwfBuf> {
frame_rate,
num_frames,
};
let data = reader.get_ref().to_vec();
let offset = reader.as_slice().as_ptr() as usize - data.as_ptr() as usize;
// Remove the header.
// As an alternative we could return the entire original buffer with header length,
// but that's a nontrivial API change, probably not worth the effort.
data.drain(..offset);
let mut reader = Reader::new(&data, version);

// Parse the first two tags, searching for the FileAttributes and SetBackgroundColor tags.
// This metadata is useful, so we want to return it along with the header.
Expand Down

0 comments on commit e9e4ceb

Please sign in to comment.