summaryrefslogtreecommitdiff
path: root/Userland/Libraries/LibCompress
diff options
context:
space:
mode:
authorIdan Horowitz <idan.horowitz@gmail.com>2021-05-18 00:26:16 +0300
committerAndreas Kling <kling@serenityos.org>2021-05-18 08:09:21 +0200
commit325febf4e534fde96c01abad4a69deb6fdc832e5 (patch)
tree3e8a0e464afce060ba930ed64875cef5deaee974 /Userland/Libraries/LibCompress
parent3ef6e31ded51964502e2702ace6443a42fef0eca (diff)
downloadserenity-325febf4e534fde96c01abad4a69deb6fdc832e5.zip
LibCompress: Discard GZip NAME & COMMENT optional strings
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.
Diffstat (limited to 'Userland/Libraries/LibCompress')
-rw-r--r--Userland/Libraries/LibCompress/Gzip.cpp21
1 files changed, 17 insertions, 4 deletions
diff --git a/Userland/Libraries/LibCompress/Gzip.cpp b/Userland/Libraries/LibCompress/Gzip.cpp
index 9d62505c2a..644718acfc 100644
--- a/Userland/Libraries/LibCompress/Gzip.cpp
+++ b/Userland/Libraries/LibCompress/Gzip.cpp
@@ -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) {