Skip to content

Commit

Permalink
LibCompress: Discard GZip NAME & COMMENT optional strings
Browse files Browse the repository at this point in the history
We now discard these strings instead of copying them into a String
which we immediately destruct. This should result in both a perf uplift
and lower memory usage.
  • Loading branch information
IdanHo authored and awesomekling committed May 18, 2021
1 parent 3ef6e31 commit 325febf
Showing 1 changed file with 17 additions and 4 deletions.
21 changes: 17 additions & 4 deletions Userland/Libraries/LibCompress/Gzip.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -118,14 +118,27 @@ size_t GzipDecompressor::read(Bytes bytes)
m_input_stream.discard_or_error(length);
}

auto discard_string = [&]() {
char next_char;
do {
m_input_stream >> next_char;
if (m_input_stream.has_any_error()) {
set_fatal_error();
break;
}
} while (next_char);
};

if (header.flags & Flags::FNAME) {
String original_filename;
m_input_stream >> original_filename;
discard_string();
if (has_any_error())
break;
}

if (header.flags & Flags::FCOMMENT) {
String comment;
m_input_stream >> comment;
discard_string();
if (has_any_error())
break;
}

if (header.flags & Flags::FHCRC) {
Expand Down

0 comments on commit 325febf

Please sign in to comment.