core, video_core: Use reserve() before loops where possible

This commit is contained in:
Herman Semenov 2024-08-22 20:21:04 +03:00
parent 79680c50c0
commit 49169fcaa3
3 changed files with 5 additions and 1 deletions

View File

@ -15,7 +15,9 @@ namespace Libraries::Kernel {
std::vector<Core::FileSys::DirEntry> GetDirectoryEntries(const std::filesystem::path& path) { std::vector<Core::FileSys::DirEntry> GetDirectoryEntries(const std::filesystem::path& path) {
std::vector<Core::FileSys::DirEntry> files; std::vector<Core::FileSys::DirEntry> files;
for (const auto& entry : std::filesystem::directory_iterator(path)) { const auto dirIt = std::filesystem::directory_iterator{path};
files.reserve(std::distance(dirIt, std::filesystem::directory_iterator{}));
for (const auto& entry : dirIt) {
auto& dir_entry = files.emplace_back(); auto& dir_entry = files.emplace_back();
dir_entry.name = entry.path().filename().string(); dir_entry.name = entry.path().filename().string();
dir_entry.isFile = !std::filesystem::is_directory(entry.path().string()); dir_entry.isFile = !std::filesystem::is_directory(entry.path().string());

View File

@ -33,6 +33,7 @@ std::vector<std::string> GetSupportedExtensions(vk::PhysicalDevice physical) {
std::unordered_map<vk::Format, vk::FormatProperties> GetFormatProperties( std::unordered_map<vk::Format, vk::FormatProperties> GetFormatProperties(
vk::PhysicalDevice physical) { vk::PhysicalDevice physical) {
std::unordered_map<vk::Format, vk::FormatProperties> format_properties; std::unordered_map<vk::Format, vk::FormatProperties> format_properties;
format_properties.reserve(LiverpoolToVK::GetAllFormats().size());
for (const auto& format : LiverpoolToVK::GetAllFormats()) { for (const auto& format : LiverpoolToVK::GetAllFormats()) {
format_properties.emplace(format, physical.getFormatProperties(format)); format_properties.emplace(format, physical.getFormatProperties(format));
} }

View File

@ -125,6 +125,7 @@ DescriptorHeap::DescriptorHeap(const Instance& instance, MasterSemaphore* master
for (const auto& binding : bindings) { for (const auto& binding : bindings) {
descriptor_type_counts[binding.descriptorType] += binding.descriptorCount; descriptor_type_counts[binding.descriptorType] += binding.descriptorCount;
} }
pool_sizes.reserve(descriptor_type_counts.size());
for (const auto& [type, count] : descriptor_type_counts) { for (const auto& [type, count] : descriptor_type_counts) {
auto& pool_size = pool_sizes.emplace_back(); auto& pool_size = pool_sizes.emplace_back();
pool_size.descriptorCount = count * descriptor_heap_count; pool_size.descriptorCount = count * descriptor_heap_count;