Merge pull request #18557 from GermanAizek/reserve-add

Using reserve in different places PPSSPP
This commit is contained in:
Henrik Rydgård 2023-12-15 12:28:21 +01:00 committed by GitHub
commit bbcaeb9d13
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
35 changed files with 59 additions and 7 deletions

View File

@ -109,6 +109,7 @@ bool ZipFileReader::GetFileListing(const char *orig_path, std::vector<File::File
INFO_LOG(SYSTEM, "Listing %s", orig_path);
listing->reserve(directories.size() + files.size());
for (auto diter = directories.begin(); diter != directories.end(); ++diter) {
File::FileInfo info;
info.name = *diter;

View File

@ -748,6 +748,7 @@ InputLayout *D3D11DrawContext::CreateInputLayout(const InputLayoutDesc &desc) {
inputLayout->desc = desc;
// Translate to D3D11 elements;
inputLayout->elements.reserve(desc.attributes.size());
for (size_t i = 0; i < desc.attributes.size(); i++) {
D3D11_INPUT_ELEMENT_DESC el;
el.AlignedByteOffset = desc.attributes[i].offset;
@ -1142,6 +1143,7 @@ Pipeline *D3D11DrawContext::CreateGraphicsPipeline(const PipelineDesc &desc, con
std::vector<D3D11ShaderModule *> shaders;
D3D11ShaderModule *vshader = nullptr;
shaders.reserve(desc.shaders.size());
for (auto iter : desc.shaders) {
iter->AddRef();

View File

@ -11,6 +11,7 @@ static std::set<GPUMemoryManager *> g_pushBuffers;
std::vector<GPUMemoryManager *> GetActiveGPUMemoryManagers() {
std::vector<GPUMemoryManager *> buffers;
std::lock_guard<std::mutex> guard(g_pushBufferListMutex);
buffers.reserve(g_pushBuffers.size());
for (auto iter : g_pushBuffers) {
buffers.push_back(iter);
}

View File

@ -1303,10 +1303,12 @@ bool OpenGLPipeline::LinkShaders(const PipelineDesc &desc) {
std::vector<GLRProgram::UniformLocQuery> queries;
int samplersToCheck;
if (!samplers_.is_empty()) {
for (int i = 0; i < (int)std::min((const uint32_t)samplers_.size(), MAX_TEXTURE_SLOTS); i++) {
int size = std::min((const uint32_t)samplers_.size(), MAX_TEXTURE_SLOTS);
queries.reserve(size);
for (int i = 0; i < size; i++) {
queries.push_back({ &locs_->samplerLocs_[i], samplers_[i].name, true });
}
samplersToCheck = (int)std::min((const uint32_t)samplers_.size(), MAX_TEXTURE_SLOTS);
samplersToCheck = size;
} else {
queries.push_back({ &locs_->samplerLocs_[0], "sampler0" });
queries.push_back({ &locs_->samplerLocs_[1], "sampler1" });
@ -1315,6 +1317,7 @@ bool OpenGLPipeline::LinkShaders(const PipelineDesc &desc) {
}
_assert_(queries.size() <= MAX_TEXTURE_SLOTS);
queries.reserve(dynamicUniforms.uniforms.size());
for (size_t i = 0; i < dynamicUniforms.uniforms.size(); ++i) {
queries.push_back({ &locs_->dynamicUniformLocs_[i], dynamicUniforms.uniforms[i].name });
}
@ -1432,6 +1435,7 @@ void OpenGLInputLayout::Compile(const InputLayoutDesc &desc) {
stride = desc.stride;
std::vector<GLRInputLayout::Entry> entries;
entries.reserve(desc.attributes.size());
for (auto &attr : desc.attributes) {
GLRInputLayout::Entry entry;
entry.location = attr.location;

View File

@ -38,6 +38,7 @@ static const double PUSH_GARBAGE_COLLECTION_DELAY = 10.0;
VulkanPushPool::VulkanPushPool(VulkanContext *vulkan, const char *name, size_t originalBlockSize, VkBufferUsageFlags usage)
: vulkan_(vulkan), name_(name), originalBlockSize_(originalBlockSize), usage_(usage) {
RegisterGPUMemoryManager(this);
blocks_.reserve(VulkanContext::MAX_INFLIGHT_FRAMES);
for (int i = 0; i < VulkanContext::MAX_INFLIGHT_FRAMES; i++) {
blocks_.push_back(CreateBlock(originalBlockSize));
blocks_.back().original = true;

View File

@ -92,6 +92,7 @@ bool VulkanQueueRunner::CreateSwapchain(VkCommandBuffer cmdInit) {
return false;
}
swapchainImages_.reserve(swapchainImageCount_);
for (uint32_t i = 0; i < swapchainImageCount_; i++) {
SwapchainImageData sc_buffer{};
sc_buffer.image = swapchainImages[i];
@ -495,6 +496,7 @@ void VulkanQueueRunner::ApplyMGSHack(std::vector<VKRStep *> &steps) {
_assert_(steps[i + copies.size()]->stepType == VKRStepType::RENDER);
// Combine the renders.
for (int j = 1; j < (int)renders.size(); j++) {
steps[i + copies.size()]->commands.reserve(renders[j]->commands.size());
for (int k = 0; k < (int)renders[j]->commands.size(); k++) {
steps[i + copies.size()]->commands.push_back(renders[j]->commands[k]);
}

View File

@ -1550,11 +1550,15 @@ std::vector<std::string> VKContext::GetFeatureList() const {
std::vector<std::string> VKContext::GetExtensionList(bool device, bool enabledOnly) const {
std::vector<std::string> extensions;
if (enabledOnly) {
for (auto &iter : (device ? vulkan_->GetDeviceExtensionsEnabled() : vulkan_->GetInstanceExtensionsEnabled())) {
const auto& enabled = (device ? vulkan_->GetDeviceExtensionsEnabled() : vulkan_->GetInstanceExtensionsEnabled());
extensions.reserve(enabled.size());
for (auto &iter : enabled) {
extensions.push_back(iter);
}
} else {
for (auto &iter : (device ? vulkan_->GetDeviceExtensionsAvailable() : vulkan_->GetInstanceExtensionsAvailable())) {
const auto& available = (device ? vulkan_->GetDeviceExtensionsAvailable() : vulkan_->GetInstanceExtensionsAvailable());
extensions.reserve(available.size());
for (auto &iter : available) {
extensions.push_back(iter.extensionName);
}
}

View File

@ -43,6 +43,7 @@ std::vector<InputMapping> tabRightKeys;
static std::unordered_map<InputDeviceID, int> uiFlipAnalogY;
static void AppendKeys(std::vector<InputMapping> &keys, const std::vector<InputMapping> &newKeys) {
keys.reserve(newKeys.size());
for (auto iter = newKeys.begin(); iter != newKeys.end(); ++iter) {
keys.push_back(*iter);
}

View File

@ -156,6 +156,7 @@ Draw::Texture *CreateTextureFromTempImage(Draw::DrawContext *draw, const TempIma
desc.mipLevels = generateMips ? potentialLevels : image.numLevels;
desc.generateMips = generateMips && potentialLevels > image.numLevels;
desc.tag = name;
desc.initData.reserve(image.numLevels);
for (int i = 0; i < image.numLevels; i++) {
desc.initData.push_back(image.levels[i]);
}

View File

@ -172,6 +172,7 @@ void IconCache::Decimate(int64_t maxSize) {
};
std::vector<SortEntry> sortEntries;
sortEntries.reserve(cache_.size());
for (auto iter : cache_) {
sortEntries.push_back({ iter.first, iter.second.usedTimeStamp, iter.second.data.size() });
}

View File

@ -591,6 +591,7 @@ void DisassemblyFunction::addOpcodeSequence(u32 start, u32 end)
DisassemblyOpcode* opcode = new DisassemblyOpcode(start,(end-start)/4);
std::lock_guard<std::recursive_mutex> guard(lock_);
entries[start] = opcode;
lineAddresses.reserve((end - start) / 4);
for (u32 pos = start; pos < end; pos += 4)
{
lineAddresses.push_back(pos);

View File

@ -52,6 +52,7 @@ namespace
std::vector<std::string> GetPSPFileList (const std::string &dirpath) {
std::vector<std::string> FileList;
auto Fileinfos = pspFileSystem.GetDirListing(dirpath);
FileList.reserve(Fileinfos.size());
for (auto it = Fileinfos.begin(); it != Fileinfos.end(); ++it) {
std::string info = (*it).name;

View File

@ -127,6 +127,7 @@ std::vector<Path> DiskCachingFileLoader::GetCachedPathsInUse() {
// This is on the file loader so that it can manage the caches_.
std::vector<Path> files;
files.reserve(caches_.size());
for (auto it : caches_) {
files.push_back(it.first);

View File

@ -651,6 +651,7 @@ std::vector<PSPFileInfo> ISOFileSystem::GetDirListing(const std::string &path, b
const std::string dot(".");
const std::string dotdot("..");
myVector.reserve(entry->children.size() - 2);
for (size_t i = 0; i < entry->children.size(); i++) {
TreeEntry *e = entry->children[i];

View File

@ -377,6 +377,7 @@ void Arm64JitBackend::CompIR_ValidateAddress(IRInst inst) {
ANDI2R(SCRATCH1, SCRATCH1, 0x3FFFFFFF, SCRATCH2);
std::vector<FixupBranch> validJumps;
validJumps.reserve(3);
FixupBranch unaligned;
if (alignment == 2) {

View File

@ -94,6 +94,7 @@ bool Arm64JitBackend::CompileBlock(IRBlock *block, int block_num, bool preload)
regs_.Start(block);
std::vector<const u8 *> addresses;
addresses.reserve(block->GetNumInstructions());
for (int i = 0; i < block->GetNumInstructions(); ++i) {
const IRInst &inst = block->GetInstructions()[i];
regs_.SetIRIndex(i);

View File

@ -410,6 +410,7 @@ JitBlockDebugInfo IRBlockCache::GetBlockDebugInfo(int blockNum) const {
ir.GetRange(start, size);
debugInfo.originalAddress = start; // TODO
debugInfo.origDisasm.reserve(((start + size) - start) / 4);
for (u32 addr = start; addr < start + size; addr += 4) {
char temp[256];
MIPSDisAsm(Memory::Read_Instruction(addr), addr, temp, sizeof(temp), true);
@ -417,6 +418,7 @@ JitBlockDebugInfo IRBlockCache::GetBlockDebugInfo(int blockNum) const {
debugInfo.origDisasm.push_back(mipsDis);
}
debugInfo.irDisasm.reserve(ir.GetNumInstructions());
for (int i = 0; i < ir.GetNumInstructions(); i++) {
IRInst inst = ir.GetInstructions()[i];
char buffer[256];

View File

@ -693,6 +693,7 @@ JitBlockDebugInfo JitBlockCache::GetBlockDebugInfo(int blockNum) const {
JitBlockDebugInfo debugInfo{};
const JitBlock *block = GetBlock(blockNum);
debugInfo.originalAddress = block->originalAddress;
debugInfo.origDisasm.reserve(((block->originalAddress + block->originalSize * 4) - block->originalAddress) / 4);
for (u32 addr = block->originalAddress; addr <= block->originalAddress + block->originalSize * 4; addr += 4) {
char temp[256];
MIPSDisAsm(Memory::Read_Instruction(addr), addr, temp, sizeof(temp), true);

View File

@ -135,6 +135,7 @@ std::vector<std::string> DisassembleArm2(const u8 *data, int size) {
char temp[256];
int bkpt_count = 0;
lines.reserve(size / 4);
for (int i = 0; i < size; i += 4) {
const u32 *codePtr = (const u32 *)(data + i);
u32 inst = codePtr[0];
@ -196,6 +197,7 @@ std::vector<std::string> DisassembleArm64(const u8 *data, int size) {
char temp[256];
int bkpt_count = 0;
lines.reserve(size / 4);
for (int i = 0; i < size; i += 4) {
const u32 *codePtr = (const u32 *)(data + i);
uint64_t addr = (intptr_t)codePtr;

View File

@ -83,6 +83,7 @@ bool RiscVJitBackend::CompileBlock(IRBlock *block, int block_num, bool preload)
regs_.Start(block);
std::vector<const u8 *> addresses;
addresses.reserve(block->GetNumInstructions());
for (int i = 0; i < block->GetNumInstructions(); ++i) {
const IRInst &inst = block->GetInstructions()[i];
regs_.SetIRIndex(i);

View File

@ -894,7 +894,7 @@ void Jit::CheckMemoryBreakpoint(int instructionOffset, MIPSGPReg rs, int offset)
SetJumpTarget(skipCheck);
}
} else {
const auto memchecks = CBreakPoints::GetMemCheckRanges(isWrite);
const auto &memchecks = CBreakPoints::GetMemCheckRanges(isWrite);
bool possible = !memchecks.empty();
if (!possible)
return;
@ -908,6 +908,7 @@ void Jit::CheckMemoryBreakpoint(int instructionOffset, MIPSGPReg rs, int offset)
FlushAll();
std::vector<FixupBranch> hitChecks;
hitChecks.reserve(memchecks.size());
for (auto it = memchecks.begin(), end = memchecks.end(); it != end; ++it) {
if (it->end != 0) {
CMP(32, R(RAX), Imm32(it->start - size));

View File

@ -455,6 +455,7 @@ void JitSafeMemFuncs::CreateWriteFunc(int bits, const void *fallbackFunc) {
void JitSafeMemFuncs::CheckDirectEAX() {
// Clear any cache/kernel bits.
AND(32, R(EAX), Imm32(0x3FFFFFFF));
skips_.reserve(3);
CMP(32, R(EAX), Imm32(PSP_GetUserMemoryEnd()));
FixupBranch tooHighRAM = J_CC(CC_AE);

View File

@ -147,7 +147,7 @@ void X64JitBackend::CompIR_Breakpoint(IRInst inst) {
}
bool isWrite = MIPSAnalyst::IsOpMemoryWrite(checkedPC);
const auto memchecks = CBreakPoints::GetMemCheckRanges(isWrite);
const auto &memchecks = CBreakPoints::GetMemCheckRanges(isWrite);
// We can trivially skip if there are no checks for this type (i.e. read vs write.)
if (memchecks.empty())
break;
@ -159,7 +159,8 @@ void X64JitBackend::CompIR_Breakpoint(IRInst inst) {
FlushAll();
std::vector<FixupBranch> hitChecks;
for (auto it : memchecks) {
hitChecks.reserve(memchecks.size());
for (const auto &it : memchecks) {
if (it.end != 0) {
CMP(32, R(SCRATCH1), Imm32(it.start - size));
FixupBranch skipNext = J_CC(CC_BE);
@ -382,6 +383,7 @@ void X64JitBackend::CompIR_ValidateAddress(IRInst inst) {
AND(32, R(SCRATCH1), Imm32(0x3FFFFFFF));
std::vector<FixupBranch> validJumps;
validJumps.reserve(3);
FixupBranch unaligned;
if (alignment != 1) {

View File

@ -9,6 +9,7 @@ GameDB g_gameDB;
static void SplitCSVLine(const std::string_view str, std::vector<std::string_view> &result) {
result.clear();
result.reserve(str.size() + 1);
int indexCommaToLeftOfColumn = 0;
int indexCommaToRightOfColumn = -1;

View File

@ -75,6 +75,7 @@ VertexDecoder *DrawEngineCommon::GetVertexDecoder(u32 vtype) {
std::vector<std::string> DrawEngineCommon::DebugGetVertexLoaderIDs() {
std::vector<std::string> ids;
ids.reserve(decoderMap_.size());
decoderMap_.Iterate([&](const uint32_t vtype, VertexDecoder *decoder) {
std::string id;
id.resize(sizeof(vtype));

View File

@ -72,6 +72,7 @@ bool GenerateFragmentShader(const FShaderID &id, char *buffer, const ShaderLangu
std::vector<const char*> extensions;
if (ShaderLanguageIsOpenGL(compat.shaderLanguage)) {
extensions.reserve(4);
if (stencilToAlpha == REPLACE_ALPHA_DUALSOURCE && gl_extensions.EXT_blend_func_extended) {
extensions.push_back("#extension GL_EXT_blend_func_extended : require");
}

View File

@ -67,6 +67,8 @@ bool GenerateGeometryShader(const GShaderID &id, char *buffer, const ShaderLangu
}
std::vector<VaryingDef> varyings, outVaryings;
varyings.reserve(4);
outVaryings.reserve(4);
if (id.Bit(GS_BIT_DO_TEXTURE)) {
varyings.push_back(VaryingDef{ "vec3", "v_texcoord", Draw::SEM_TEXCOORD0, 0, "highp" });

View File

@ -136,6 +136,7 @@ bool GenerateVertexShader(const VShaderID &id, char *buffer, const ShaderLanguag
bool highpTexcoord = false;
std::vector<const char*> extensions;
extensions.reserve(6);
if (ShaderLanguageIsOpenGL(compat.shaderLanguage)) {
if (gl_extensions.EXT_gpu_shader4) {
extensions.push_back("#extension GL_EXT_gpu_shader4 : enable");

View File

@ -251,6 +251,7 @@ std::vector<std::string> ShaderManagerD3D11::DebugGetShaderIDs(DebugShaderType t
switch (type) {
case SHADER_TYPE_VERTEX:
{
ids.reserve(vsCache_.size());
for (auto iter : vsCache_) {
iter.first.ToString(&id);
ids.push_back(id);
@ -259,6 +260,7 @@ std::vector<std::string> ShaderManagerD3D11::DebugGetShaderIDs(DebugShaderType t
}
case SHADER_TYPE_FRAGMENT:
{
ids.reserve(fsCache_.size());
for (auto iter : fsCache_) {
iter.first.ToString(&id);
ids.push_back(id);

View File

@ -667,6 +667,7 @@ std::vector<std::string> ShaderManagerDX9::DebugGetShaderIDs(DebugShaderType typ
switch (type) {
case SHADER_TYPE_VERTEX:
{
ids.reserve(vsCache_.size());
for (auto iter : vsCache_) {
iter.first.ToString(&id);
ids.push_back(id);
@ -675,6 +676,7 @@ std::vector<std::string> ShaderManagerDX9::DebugGetShaderIDs(DebugShaderType typ
break;
case SHADER_TYPE_FRAGMENT:
{
ids.reserve(fsCache_.size());
for (auto iter : fsCache_) {
iter.first.ToString(&id);
ids.push_back(id);

View File

@ -103,6 +103,7 @@ void DrawEngineGLES::InitDeviceObjects() {
int stride = sizeof(TransformedVertex);
std::vector<GLRInputLayout::Entry> entries;
entries.reserve(5);
entries.push_back({ ATTR_POSITION, 4, GL_FLOAT, GL_FALSE, offsetof(TransformedVertex, x) });
entries.push_back({ ATTR_TEXCOORD, 3, GL_FLOAT, GL_FALSE, offsetof(TransformedVertex, u) });
entries.push_back({ ATTR_COLOR0, 4, GL_UNSIGNED_BYTE, GL_TRUE, offsetof(TransformedVertex, color0) });

View File

@ -915,6 +915,7 @@ std::vector<std::string> ShaderManagerGLES::DebugGetShaderIDs(DebugShaderType ty
switch (type) {
case SHADER_TYPE_VERTEX:
{
ids.reserve(vsCache_.size());
vsCache_.Iterate([&](const VShaderID &id, Shader *shader) {
std::string idstr;
id.ToString(&idstr);
@ -924,6 +925,7 @@ std::vector<std::string> ShaderManagerGLES::DebugGetShaderIDs(DebugShaderType ty
break;
case SHADER_TYPE_FRAGMENT:
{
ids.reserve(fsCache_.size());
fsCache_.Iterate([&](const FShaderID &id, Shader *shader) {
std::string idstr;
id.ToString(&idstr);

View File

@ -402,6 +402,7 @@ std::vector<std::string> PipelineManagerVulkan::DebugGetObjectIDs(DebugShaderTyp
switch (type) {
case SHADER_TYPE_PIPELINE:
{
ids.reserve(pipelines_.size());
pipelines_.Iterate([&](const VulkanPipelineKey &key, VulkanPipeline *value) {
std::string id;
key.ToString(&id);

View File

@ -394,6 +394,7 @@ std::vector<std::string> ShaderManagerVulkan::DebugGetShaderIDs(DebugShaderType
switch (type) {
case SHADER_TYPE_VERTEX:
{
ids.reserve(vsCache_.size());
vsCache_.Iterate([&](const VShaderID &id, VulkanVertexShader *shader) {
std::string idstr;
id.ToString(&idstr);
@ -403,6 +404,7 @@ std::vector<std::string> ShaderManagerVulkan::DebugGetShaderIDs(DebugShaderType
}
case SHADER_TYPE_FRAGMENT:
{
ids.reserve(fsCache_.size());
fsCache_.Iterate([&](const FShaderID &id, VulkanFragmentShader *shader) {
std::string idstr;
id.ToString(&idstr);
@ -412,6 +414,7 @@ std::vector<std::string> ShaderManagerVulkan::DebugGetShaderIDs(DebugShaderType
}
case SHADER_TYPE_GEOMETRY:
{
ids.reserve(gsCache_.size());
gsCache_.Iterate([&](const GShaderID &id, VulkanGeometryShader *shader) {
std::string idstr;
id.ToString(&idstr);

View File

@ -187,6 +187,7 @@ void SamplerCache::DeviceRestore(VulkanContext *vulkan) {
std::vector<std::string> SamplerCache::DebugGetSamplerIDs() const {
std::vector<std::string> ids;
ids.reserve(cache_.size());
cache_.Iterate([&](const SamplerCacheKey &id, VkSampler sampler) {
std::string idstr;
id.ToString(&idstr);