Skip to content

Commit

Permalink
Merge pull request #18630 from hrydgard/more-feedback
Browse files Browse the repository at this point in the history
Remove excessive .reserve calls, remove unexplained check
  • Loading branch information
hrydgard committed Dec 29, 2023
2 parents c97d5ef + 6aaf9b0 commit 9e82b12
Show file tree
Hide file tree
Showing 26 changed files with 15 additions and 67 deletions.
2 changes: 0 additions & 2 deletions Common/GPU/D3D11/thin3d_d3d11.cpp
Expand Up @@ -748,7 +748,6 @@ 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;
Expand Down Expand Up @@ -1143,7 +1142,6 @@ 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();

Expand Down
1 change: 0 additions & 1 deletion Common/GPU/GPUBackendCommon.cpp
Expand Up @@ -11,7 +11,6 @@ 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);
}
Expand Down
1 change: 0 additions & 1 deletion Common/GPU/OpenGL/thin3d_gl.cpp
Expand Up @@ -1435,7 +1435,6 @@ 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;
Expand Down
1 change: 0 additions & 1 deletion Common/GPU/Vulkan/VulkanMemory.cpp
Expand Up @@ -38,7 +38,6 @@ 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;
Expand Down
1 change: 0 additions & 1 deletion Common/GPU/Vulkan/VulkanQueueRunner.cpp
Expand Up @@ -92,7 +92,6 @@ 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];
Expand Down
1 change: 0 additions & 1 deletion Common/Input/InputState.cpp
Expand Up @@ -43,7 +43,6 @@ 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);
}
Expand Down
1 change: 0 additions & 1 deletion Common/Render/ManagedTexture.cpp
Expand Up @@ -156,7 +156,6 @@ 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]);
}
Expand Down
7 changes: 1 addition & 6 deletions Core/Debugger/MemBlockInfo.cpp
Expand Up @@ -288,12 +288,7 @@ void MemSlabMap::Clear() {

MemSlabMap::Slab *MemSlabMap::FindSlab(uint32_t addr) {
// Jump ahead using our index.
size_t slabIndex = addr / SLICE_SIZE;
if (slabIndex >= heads_.size()) {
// Shouldn't happen, but apparently can.
return nullptr;
}
Slab *slab = heads_[slabIndex];
Slab *slab = heads_[addr / SLICE_SIZE];
// We often move forward, so check the last find.
if (lastFind_->start > slab->start && lastFind_->start <= addr)
slab = lastFind_;
Expand Down
1 change: 0 additions & 1 deletion Core/HLE/proAdhoc.cpp
Expand Up @@ -1891,7 +1891,6 @@ uint32_t getLocalIp(int sock) {
static std::vector<std::pair<uint32_t, uint32_t>> InitPrivateIPRanges() {
struct sockaddr_in saNet {}, saMask{};
std::vector<std::pair<uint32_t, uint32_t>> ip_ranges;
ip_ranges.reserve(5);

if (1 == inet_pton(AF_INET, "192.168.0.0", &(saNet.sin_addr)) && 1 == inet_pton(AF_INET, "255.255.0.0", &(saMask.sin_addr)))
ip_ranges.push_back({saNet.sin_addr.s_addr, saMask.sin_addr.s_addr});
Expand Down
1 change: 0 additions & 1 deletion Core/MIPS/ARM64/Arm64IRCompSystem.cpp
Expand Up @@ -386,7 +386,6 @@ void Arm64JitBackend::CompIR_ValidateAddress(IRInst inst) {
ANDI2R(SCRATCH1, SCRATCH1, 0x3FFFFFFF, SCRATCH2);

std::vector<FixupBranch> validJumps;
validJumps.reserve(3);

FixupBranch unaligned;
if (alignment == 2) {
Expand Down
1 change: 0 additions & 1 deletion Core/MIPS/MIPSAnalyst.cpp
Expand Up @@ -1415,7 +1415,6 @@ namespace MIPSAnalyst {

std::vector<MIPSGPReg> GetOutputRegs(MIPSOpcode op) {
std::vector<MIPSGPReg> vec;
vec.reserve(3);
MIPSInfo info = MIPSGetInfo(op);
if (info & OUT_RD) vec.push_back(MIPS_GET_RD(op));
if (info & OUT_RT) vec.push_back(MIPS_GET_RT(op));
Expand Down
1 change: 0 additions & 1 deletion Core/MIPS/RiscV/RiscVJit.cpp
Expand Up @@ -83,7 +83,6 @@ 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);
Expand Down
2 changes: 1 addition & 1 deletion Core/MIPS/x86/Jit.cpp
Expand Up @@ -904,7 +904,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;
Expand Down
1 change: 0 additions & 1 deletion Core/MIPS/x86/JitSafeMem.cpp
Expand Up @@ -455,7 +455,6 @@ 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);
Expand Down
4 changes: 1 addition & 3 deletions Core/MIPS/x86/X64IRCompSystem.cpp
Expand Up @@ -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;
Expand All @@ -159,7 +159,6 @@ void X64JitBackend::CompIR_Breakpoint(IRInst inst) {
FlushAll();

std::vector<FixupBranch> hitChecks;
hitChecks.reserve(memchecks.size());
for (const auto &it : memchecks) {
if (it.end != 0) {
CMP(32, R(SCRATCH1), Imm32(it.start - size));
Expand Down Expand Up @@ -396,7 +395,6 @@ void X64JitBackend::CompIR_ValidateAddress(IRInst inst) {
AND(32, R(SCRATCH1), Imm32(0x3FFFFFFF));

std::vector<FixupBranch> validJumps;
validJumps.reserve(3);

FixupBranch unaligned;
if (alignment != 1) {
Expand Down
1 change: 0 additions & 1 deletion Core/Util/GameDB.cpp
Expand Up @@ -9,7 +9,6 @@ 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;
Expand Down
1 change: 0 additions & 1 deletion GPU/Common/DrawEngineCommon.cpp
Expand Up @@ -75,7 +75,6 @@ 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));
Expand Down
1 change: 0 additions & 1 deletion GPU/Common/FragmentShaderGenerator.cpp
Expand Up @@ -72,7 +72,6 @@ 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");
}
Expand Down
2 changes: 0 additions & 2 deletions GPU/Common/GeometryShaderGenerator.cpp
Expand Up @@ -67,8 +67,6 @@ 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" });
Expand Down
2 changes: 0 additions & 2 deletions GPU/D3D11/ShaderManagerD3D11.cpp
Expand Up @@ -251,7 +251,6 @@ 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);
Expand All @@ -260,7 +259,6 @@ 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);
Expand Down
10 changes: 2 additions & 8 deletions GPU/Directx9/ShaderManagerDX9.cpp
Expand Up @@ -666,23 +666,17 @@ std::vector<std::string> ShaderManagerDX9::DebugGetShaderIDs(DebugShaderType typ
std::vector<std::string> ids;
switch (type) {
case SHADER_TYPE_VERTEX:
{
ids.reserve(vsCache_.size());
for (auto iter : vsCache_) {
iter.first.ToString(&id);
ids.push_back(id);
}
}
break;
break;
case SHADER_TYPE_FRAGMENT:
{
ids.reserve(fsCache_.size());
for (auto iter : fsCache_) {
iter.first.ToString(&id);
ids.push_back(id);
}
}
break;
break;
}
return ids;
}
Expand Down
1 change: 0 additions & 1 deletion GPU/GLES/DrawEngineGLES.cpp
Expand Up @@ -103,7 +103,6 @@ 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) });
Expand Down
26 changes: 10 additions & 16 deletions GPU/GLES/ShaderManagerGLES.cpp
Expand Up @@ -914,24 +914,18 @@ std::vector<std::string> ShaderManagerGLES::DebugGetShaderIDs(DebugShaderType ty
std::vector<std::string> ids;
switch (type) {
case SHADER_TYPE_VERTEX:
{
ids.reserve(vsCache_.size());
vsCache_.Iterate([&](const VShaderID &id, Shader *shader) {
std::string idstr;
id.ToString(&idstr);
ids.push_back(idstr);
});
}
vsCache_.Iterate([&](const VShaderID &id, Shader *shader) {
std::string idstr;
id.ToString(&idstr);
ids.push_back(idstr);
});
break;
case SHADER_TYPE_FRAGMENT:
{
ids.reserve(fsCache_.size());
fsCache_.Iterate([&](const FShaderID &id, Shader *shader) {
std::string idstr;
id.ToString(&idstr);
ids.push_back(idstr);
});
}
fsCache_.Iterate([&](const FShaderID &id, Shader *shader) {
std::string idstr;
id.ToString(&idstr);
ids.push_back(idstr);
});
break;
default:
break;
Expand Down
9 changes: 0 additions & 9 deletions GPU/Vulkan/ShaderManagerVulkan.cpp
Expand Up @@ -393,35 +393,26 @@ std::vector<std::string> ShaderManagerVulkan::DebugGetShaderIDs(DebugShaderType
std::vector<std::string> ids;
switch (type) {
case SHADER_TYPE_VERTEX:
{
ids.reserve(vsCache_.size());
vsCache_.Iterate([&](const VShaderID &id, VulkanVertexShader *shader) {
std::string idstr;
id.ToString(&idstr);
ids.push_back(idstr);
});
break;
}
case SHADER_TYPE_FRAGMENT:
{
ids.reserve(fsCache_.size());
fsCache_.Iterate([&](const FShaderID &id, VulkanFragmentShader *shader) {
std::string idstr;
id.ToString(&idstr);
ids.push_back(idstr);
});
break;
}
case SHADER_TYPE_GEOMETRY:
{
ids.reserve(gsCache_.size());
gsCache_.Iterate([&](const GShaderID &id, VulkanGeometryShader *shader) {
std::string idstr;
id.ToString(&idstr);
ids.push_back(idstr);
});
break;
}
default:
break;
}
Expand Down
1 change: 0 additions & 1 deletion GPU/Vulkan/TextureCacheVulkan.cpp
Expand Up @@ -187,7 +187,6 @@ 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);
Expand Down
2 changes: 0 additions & 2 deletions Windows/Debugger/CtrlMemView.cpp
Expand Up @@ -850,7 +850,6 @@ std::vector<u32> CtrlMemView::searchString(const std::string &searchQuery) {
return searchResAddrs;

std::vector<std::pair<u32, u32>> memoryAreas;
memoryAreas.reserve(3);
memoryAreas.emplace_back(PSP_GetScratchpadMemoryBase(), PSP_GetScratchpadMemoryEnd());
// Ignore the video memory mirrors.
memoryAreas.emplace_back(PSP_GetVidMemBase(), 0x04200000);
Expand Down Expand Up @@ -901,7 +900,6 @@ void CtrlMemView::search(bool continueSearch) {
}

std::vector<std::pair<u32, u32>> memoryAreas;
memoryAreas.reserve(3);
// Ignore the video memory mirrors.
memoryAreas.emplace_back(PSP_GetVidMemBase(), 0x04200000);
memoryAreas.emplace_back(PSP_GetKernelMemoryBase(), PSP_GetUserMemoryEnd());
Expand Down

0 comments on commit 9e82b12

Please sign in to comment.