diff options
author | Vas Crabb <vas@vastheman.com> | 2021-08-29 23:39:43 +1000 |
---|---|---|
committer | Vas Crabb <vas@vastheman.com> | 2021-08-29 23:39:43 +1000 |
commit | a10ce5e161db54c98ef8255bf43132f9bc745d9e (patch) | |
tree | b5bbc33149ea920ee1339e34884ec87e5f54d480 /src/lib | |
parent | c833c1e2ed65496c29e1d8370f1de8db422b160d (diff) |
Miscellaneous clean-up.
* play_1.cpp: Use output finders.
* s3.cpp, s4.cpp, s6.cpp, s6a.cpp: Use output finders, reduced tag
lookups.
* taito_z.cpp: Use output finders, split up state class a little.
* util/unzip.cpp: Use std::optional to make code clearer.
* util/ioprocsfilter.cpp: Work around MSVC DevCom-1516410.
Diffstat (limited to 'src/lib')
-rw-r--r-- | src/lib/util/ioprocsfilter.cpp | 4 | ||||
-rw-r--r-- | src/lib/util/unzip.cpp | 42 |
2 files changed, 24 insertions, 22 deletions
diff --git a/src/lib/util/ioprocsfilter.cpp b/src/lib/util/ioprocsfilter.cpp index da67b8c41f2..b25c0493ab1 100644 --- a/src/lib/util/ioprocsfilter.cpp +++ b/src/lib/util/ioprocsfilter.cpp @@ -105,7 +105,9 @@ private: class inflate_data : private zlib_data { protected: - using zlib_data::zlib_data; + inflate_data(std::size_t buffer_size) noexcept : zlib_data(buffer_size) + { + } ~inflate_data() { diff --git a/src/lib/util/unzip.cpp b/src/lib/util/unzip.cpp index d7df8fa5ce9..1e18b4c2b7c 100644 --- a/src/lib/util/unzip.cpp +++ b/src/lib/util/unzip.cpp @@ -31,6 +31,7 @@ #include <cstdlib> #include <ctime> #include <mutex> +#include <optional> #include <ratio> #include <utility> #include <vector> @@ -210,12 +211,9 @@ public: std::chrono::system_clock::time_point current_last_modified() const noexcept { - if (!m_header.modified_cached) - { + if (!m_header.modified) m_header.modified = decode_dos_time(m_header.modified_date, m_header.modified_time); - m_header.modified_cached = true; - } - return m_header.modified; + return *m_header.modified; } std::uint32_t current_crc() const noexcept { return m_header.crc; } @@ -293,26 +291,29 @@ private: struct file_header { + private: + using optional_time_point = std::optional<std::chrono::system_clock::time_point>; + + public: file_header() noexcept { } file_header(file_header const &) = default; file_header(file_header &&) noexcept = default; file_header &operator=(file_header const &) = default; file_header &operator=(file_header &&) noexcept = default; - std::uint16_t version_created; // version made by - std::uint16_t version_needed; // version needed to extract - std::uint16_t bit_flag; // general purpose bit flag - std::uint16_t compression; // compression method - mutable std::chrono::system_clock::time_point modified; // last mod file date/time - std::uint32_t crc; // crc-32 - std::uint64_t compressed_length; // compressed size - std::uint64_t uncompressed_length; // uncompressed size - std::uint32_t start_disk_number; // disk number start - std::uint64_t local_header_offset; // relative offset of local header - std::string file_name; // file name - - std::uint16_t modified_date, modified_time; - mutable bool modified_cached; + std::uint16_t version_created; // version made by + std::uint16_t version_needed; // version needed to extract + std::uint16_t bit_flag; // general purpose bit flag + std::uint16_t compression; // compression method + mutable optional_time_point modified; // last mod file date/time + std::uint32_t crc; // crc-32 + std::uint64_t compressed_length; // compressed size + std::uint64_t uncompressed_length; // uncompressed size + std::uint32_t start_disk_number; // disk number start + std::uint64_t local_header_offset; // relative offset of local header + std::string file_name; // file name + + std::uint16_t modified_date, modified_time; }; // contains extracted end of central directory information @@ -798,7 +799,7 @@ int zip_file_impl::search(std::uint32_t search_crc, std::string_view search_file // don't immediately decode DOS timestamp - it's expensive header.modified_date = reader.modified_date(); header.modified_time = reader.modified_time(); - header.modified_cached = false; + header.modified = std::nullopt; // copy the filename bool is_utf8(general_flag_reader(header.bit_flag).utf8_encoding()); @@ -850,7 +851,6 @@ int zip_file_impl::search(std::uint32_t search_crc, std::string_view search_file try { header.modified = system_clock_time_point_from_ntfs_duration(ticks); - header.modified_cached = true; } catch (...) { |