From 8c6e0866e0194465a77560ed887edcb4c78cffb2 Mon Sep 17 00:00:00 2001 From: elsid Date: Tue, 30 Jan 2024 01:47:49 +0100 Subject: [PATCH] Avoid seek for detecting BSA type Seek is pretty expensive operation. Try to read first 12 bytes instead. --- components/bsa/bsa_file.cpp | 18 ++++-------------- 1 file changed, 4 insertions(+), 14 deletions(-) diff --git a/components/bsa/bsa_file.cpp b/components/bsa/bsa_file.cpp index c8b0021152..4704e6e7e0 100644 --- a/components/bsa/bsa_file.cpp +++ b/components/bsa/bsa_file.cpp @@ -325,25 +325,15 @@ BsaVersion Bsa::BSAFile::detectVersion(const std::filesystem::path& filePath) { std::ifstream input(filePath, std::ios_base::binary); - // Total archive size - std::streamoff fsize = 0; - if (input.seekg(0, std::ios_base::end)) - { - fsize = input.tellg(); - input.seekg(0); - } - - if (fsize < 12) - { - return BsaVersion::Unknown; - } - // Get essential header numbers // First 12 bytes uint32_t head[3]; - input.read(reinterpret_cast(head), 12); + input.read(reinterpret_cast(head), sizeof(head)); + + if (input.gcount() != sizeof(head)) + return BsaVersion::Unknown; if (head[0] == static_cast(BsaVersion::Uncompressed)) {