summaryrefslogtreecommitdiff
path: root/src/render/OpenGL.cpp
diff options
context:
space:
mode:
authorTom Englund <tomenglund26@gmail.com>2025-01-19 10:38:42 +0000
committerGitHub <noreply@github.com>2025-01-19 10:38:42 +0000
commit4da9b7cc5b50c346309378fbb5ae8aa07746fd33 (patch)
treea618fb83c13bac02729751d866a884e7207d08e7 /src/render/OpenGL.cpp
parentf56153a9c1b0a00fac0932a95e0cfa5a4f6c681f (diff)
core: reserve vector sizes as much as we can (#9118)
avoid reallocations as much as possible with a few edge cases where the reservation overshoots a tiny bit. but a few bytes of memory short term is better used then the overhead of potential reallocation.
Diffstat (limited to 'src/render/OpenGL.cpp')
-rw-r--r--src/render/OpenGL.cpp14
1 files changed, 11 insertions, 3 deletions
diff --git a/src/render/OpenGL.cpp b/src/render/OpenGL.cpp
index c5bb3620..ceb94c81 100644
--- a/src/render/OpenGL.cpp
+++ b/src/render/OpenGL.cpp
@@ -400,7 +400,10 @@ std::optional<std::vector<uint64_t>> CHyprOpenGLImpl::getModsForFormat(EGLint fo
m_sProc.eglQueryDmaBufModifiersEXT(m_pEglDisplay, format, len, mods.data(), external.data(), &len);
std::vector<uint64_t> result;
- bool linearIsExternal = false;
+ // reserve number of elements to avoid reallocations
+ result.reserve(mods.size());
+
+ bool linearIsExternal = false;
for (size_t i = 0; i < mods.size(); ++i) {
if (external.at(i)) {
if (mods.at(i) == DRM_FORMAT_MOD_LINEAR)
@@ -449,6 +452,8 @@ void CHyprOpenGLImpl::initDRMFormats() {
Debug::log(LOG, "Supported DMA-BUF formats:");
std::vector<SDRMFormat> dmaFormats;
+ // reserve number of elements to avoid reallocations
+ dmaFormats.reserve(formats.size());
for (auto const& fmt : formats) {
std::vector<uint64_t> mods;
@@ -472,8 +477,10 @@ void CHyprOpenGLImpl::initDRMFormats() {
});
std::vector<std::pair<uint64_t, std::string>> modifierData;
+ // reserve number of elements to avoid reallocations
+ modifierData.reserve(mods.size());
- auto fmtName = drmGetFormatName(fmt);
+ auto fmtName = drmGetFormatName(fmt);
Debug::log(LOG, "EGL: GPU Supports Format {} (0x{:x})", fmtName ? fmtName : "?unknown?", fmt);
for (auto const& mod : mods) {
auto modName = drmGetFormatModifierName(mod);
@@ -2942,7 +2949,8 @@ SP<CEGLSync> CHyprOpenGLImpl::createEGLSync(int fenceFD) {
Debug::log(ERR, "createEGLSync: dup failed");
return nullptr;
}
-
+ // reserve number of elements to avoid reallocations
+ attribs.reserve(3);
attribs.push_back(EGL_SYNC_NATIVE_FENCE_FD_ANDROID);
attribs.push_back(dupFd);
attribs.push_back(EGL_NONE);