mirror of
https://github.com/OpenMW/openmw.git
synced 2025-12-12 18:43:08 +00:00
Only reserve capacity when reading collections
But do not initialize. If the meta information is invalid and has a big value, initialization will take significant amount of time but there might be no actual data in the file because it's too small.
This commit is contained in:
parent
38f6c5a68b
commit
9a449ed506
2 changed files with 22 additions and 9 deletions
|
|
@ -161,11 +161,11 @@ void BSAFile::readHeader()
|
|||
size_t fileDataOffset = 12 + dirsize + 8 * filenum;
|
||||
|
||||
// Set up the the FileStruct table
|
||||
mFiles.resize(filenum);
|
||||
mFiles.reserve(filenum);
|
||||
size_t endOfNameBuffer = 0;
|
||||
for (size_t i = 0; i < filenum; i++)
|
||||
{
|
||||
FileStruct& fs = mFiles[i];
|
||||
FileStruct& fs = mFiles.emplace_back();
|
||||
|
||||
const uint32_t fileSize = offsets[i * 2];
|
||||
const uint32_t offset = offsets[i * 2 + 1] + static_cast<uint32_t>(fileDataOffset);
|
||||
|
|
|
|||
|
|
@ -82,9 +82,12 @@ namespace Bsa
|
|||
};
|
||||
|
||||
std::vector<std::pair<FlatFolderRecord, std::vector<FileRecord>>> folders;
|
||||
folders.resize(mHeader.mFolderCount);
|
||||
for (auto& [folder, filelist] : folders)
|
||||
folders.reserve(mHeader.mFolderCount);
|
||||
|
||||
for (std::uint32_t i = 0; i < mHeader.mFolderCount; ++i)
|
||||
{
|
||||
FlatFolderRecord folder;
|
||||
|
||||
input.read(reinterpret_cast<char*>(&folder.mHash), 8);
|
||||
input.read(reinterpret_cast<char*>(&folder.mCount), 4);
|
||||
if (mHeader.mVersion == Version_SSE) // SSE
|
||||
|
|
@ -97,10 +100,12 @@ namespace Bsa
|
|||
{
|
||||
input.read(reinterpret_cast<char*>(&folder.mOffset), 4);
|
||||
}
|
||||
}
|
||||
|
||||
if (input.bad())
|
||||
fail("Failed to read compressed BSA folder records: input error");
|
||||
if (input.fail())
|
||||
fail("Failed to read compressed BSA folder records: input error");
|
||||
|
||||
folders.emplace_back(std::move(folder), std::vector<FileRecord>());
|
||||
}
|
||||
|
||||
// file record blocks
|
||||
if ((mHeader.mFlags & ArchiveFlag_FolderNames) == 0)
|
||||
|
|
@ -127,12 +132,20 @@ namespace Bsa
|
|||
mHeader.mFolderNamesLength -= size;
|
||||
}
|
||||
|
||||
filelist.resize(folder.mCount);
|
||||
for (auto& file : filelist)
|
||||
filelist.reserve(folder.mCount);
|
||||
|
||||
for (std::uint32_t i = 0; i < folder.mCount; ++i)
|
||||
{
|
||||
FileRecord file;
|
||||
|
||||
input.read(reinterpret_cast<char*>(&file.mHash), 8);
|
||||
input.read(reinterpret_cast<char*>(&file.mSize), 4);
|
||||
input.read(reinterpret_cast<char*>(&file.mOffset), 4);
|
||||
|
||||
if (input.fail())
|
||||
fail("Failed to read compressed BSA folder file records: input error");
|
||||
|
||||
filelist.push_back(std::move(file));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue