misc: make for loops const reference (#66)

we all like the dreams and prayers that compilers can optimize things
further with const.
This commit is contained in:
Tom Englund 2024-08-27 20:04:26 +02:00 committed by GitHub
parent abb3c81c59
commit 7cc3d3179c
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
11 changed files with 62 additions and 62 deletions

View file

@ -35,7 +35,7 @@ static SDRMFormat guessFormatFrom(std::vector<SDRMFormat> formats, bool cursor)
if (auto it = std::find_if(formats.begin(), formats.end(), [](const auto& f) { return f.drmFormat == DRM_FORMAT_XRGB8888; }); it != formats.end())
return *it;
for (auto& f : formats) {
for (auto const& f : formats) {
auto name = fourccToName(f.drmFormat);
/* 10 bpp RGB */
@ -43,7 +43,7 @@ static SDRMFormat guessFormatFrom(std::vector<SDRMFormat> formats, bool cursor)
return f;
}
for (auto& f : formats) {
for (auto const& f : formats) {
auto name = fourccToName(f.drmFormat);
/* 8 bpp RGB */
@ -93,11 +93,11 @@ Aquamarine::CGBMBuffer::CGBMBuffer(const SAllocatorBufferParams& params, Hypruti
if (!RENDERABLE.empty()) {
TRACE(allocator->backend->log(AQ_LOG_TRACE, std::format("GBM: Renderable has {} formats, clipping", RENDERABLE.size())));
for (auto& f : FORMATS) {
for (auto const& f : FORMATS) {
if (f.drmFormat != attrs.format)
continue;
for (auto& m : f.modifiers) {
for (auto const& m : f.modifiers) {
if (m == DRM_FORMAT_MOD_INVALID)
continue;
@ -141,7 +141,7 @@ Aquamarine::CGBMBuffer::CGBMBuffer(const SAllocatorBufferParams& params, Hypruti
bo = gbm_bo_create(allocator->gbmDevice, attrs.size.x, attrs.size.y, attrs.format, flags);
} else {
TRACE(allocator->backend->log(AQ_LOG_TRACE, std::format("GBM: Using modifier-based allocation, modifiers: {}", explicitModifiers.size())));
for (auto& mod : explicitModifiers) {
for (auto const& mod : explicitModifiers) {
TRACE(allocator->backend->log(AQ_LOG_TRACE, std::format("GBM: | mod 0x{:x}", mod)));
}
bo = gbm_bo_create_with_modifiers2(allocator->gbmDevice, attrs.size.x, attrs.size.y, attrs.format, explicitModifiers.data(), explicitModifiers.size(), flags);

View file

@ -67,7 +67,7 @@ Hyprutils::Memory::CSharedPointer<CBackend> Aquamarine::CBackend::create(const s
backend->log(AQ_LOG_DEBUG, "Creating an Aquamarine backend!");
for (auto& b : backends) {
for (auto const& b : backends) {
if (b.backendType == AQ_BACKEND_WAYLAND) {
auto ref = SP<CWaylandBackend>(new CWaylandBackend(backend));
backend->implementations.emplace_back(ref);
@ -79,7 +79,7 @@ Hyprutils::Memory::CSharedPointer<CBackend> Aquamarine::CBackend::create(const s
continue;
}
for (auto& r : ref) {
for (auto const& r : ref) {
backend->implementations.emplace_back(r);
}
} else if (b.backendType == AQ_BACKEND_HEADLESS) {
@ -109,7 +109,7 @@ bool Aquamarine::CBackend::start() {
int started = 0;
auto optionsForType = [this](eBackendType type) -> SBackendImplementationOptions {
for (auto& o : implementationOptions) {
for (auto const& o : implementationOptions) {
if (o.backendType == type)
return o;
}
@ -145,7 +145,7 @@ bool Aquamarine::CBackend::start() {
});
// TODO: obviously change this when (if) we add different allocators.
for (auto& b : implementations) {
for (auto const& b : implementations) {
if (b->drmFD() >= 0) {
auto fd = reopenDRMNode(b->drmFD());
if (fd < 0) {
@ -162,7 +162,7 @@ bool Aquamarine::CBackend::start() {
return false;
ready = true;
for (auto& b : implementations) {
for (auto const& b : implementations) {
b->onReady();
}
@ -180,15 +180,15 @@ void Aquamarine::CBackend::log(eBackendLogLevel level, const std::string& msg) {
std::vector<Hyprutils::Memory::CSharedPointer<SPollFD>> Aquamarine::CBackend::getPollFDs() {
std::vector<Hyprutils::Memory::CSharedPointer<SPollFD>> result;
for (auto& i : implementations) {
for (auto const& i : implementations) {
auto pollfds = i->pollFDs();
for (auto& p : pollfds) {
for (auto const& p : pollfds) {
log(AQ_LOG_DEBUG, std::format("backend: poll fd {} for implementation {}", p->fd, backendTypeToName(i->type())));
result.emplace_back(p);
}
}
for (auto& sfd : sessionFDs) {
for (auto const& sfd : sessionFDs) {
log(AQ_LOG_DEBUG, std::format("backend: poll fd {} for session", sfd->fd));
result.emplace_back(sfd);
}
@ -200,7 +200,7 @@ std::vector<Hyprutils::Memory::CSharedPointer<SPollFD>> Aquamarine::CBackend::ge
}
int Aquamarine::CBackend::drmFD() {
for (auto& i : implementations) {
for (auto const& i : implementations) {
int fd = i->drmFD();
if (fd < 0)
continue;
@ -215,14 +215,14 @@ bool Aquamarine::CBackend::hasSession() {
}
std::vector<SDRMFormat> Aquamarine::CBackend::getPrimaryRenderFormats() {
for (auto& b : implementations) {
for (auto const& b : implementations) {
if (b->type() != AQ_BACKEND_DRM && b->type() != AQ_BACKEND_WAYLAND)
continue;
return b->getRenderFormats();
}
for (auto& b : implementations) {
for (auto const& b : implementations) {
return b->getRenderFormats();
}
@ -260,7 +260,7 @@ void Aquamarine::CBackend::dispatchIdle() {
auto cpy = idle.pending;
idle.pending.clear();
for (auto& i : cpy) {
for (auto const& i : cpy) {
if (i && *i)
(*i)();
}

View file

@ -149,7 +149,7 @@ void Aquamarine::CHeadlessBackend::dispatchTimers() {
}
}
for (auto& copy : toFire) {
for (auto const& copy : toFire) {
if (copy.what)
copy.what();
}
@ -162,7 +162,7 @@ void Aquamarine::CHeadlessBackend::updateTimerFD() {
const auto clocknow = std::chrono::steady_clock::now();
bool any = false;
for (auto& t : timers.timers) {
for (auto const& t : timers.timers) {
auto delta = std::chrono::duration_cast<std::chrono::microseconds>(t.when - clocknow).count() * 1000 /* µs -> ns */;
if (delta < lowestNs)

View file

@ -264,7 +264,7 @@ static bool isDRMCard(const char* sysname) {
}
void Aquamarine::CSession::onReady() {
for (auto& d : libinputDevices) {
for (auto const& d : libinputDevices) {
if (d->keyboard)
backend->events.newKeyboard.emit(SP<IKeyboard>(d->keyboard));
if (d->mouse)
@ -278,7 +278,7 @@ void Aquamarine::CSession::onReady() {
if (d->tabletPad)
backend->events.newTabletPad.emit(SP<ITabletPad>(d->tabletPad));
for (auto& t : d->tabletTools) {
for (auto const& t : d->tabletTools) {
backend->events.newTabletTool.emit(SP<ITabletTool>(t));
}
}
@ -306,7 +306,7 @@ void Aquamarine::CSession::dispatchUdevEvents() {
dev_t deviceNum = udev_device_get_devnum(device);
SP<CSessionDevice> sessionDevice;
for (auto& sDev : sessionDevices) {
for (auto const& sDev : sessionDevices) {
if (sDev->dev == deviceNum) {
sessionDevice = sDev;
break;
@ -498,7 +498,7 @@ void Aquamarine::CSession::handleLibinputEvent(libinput_event* e) {
LIBINPUT_POINTER_AXIS_SCROLL_HORIZONTAL,
};
for (auto& axis : LAXES) {
for (auto const& axis : LAXES) {
if (!libinput_event_pointer_has_axis(pe, axis))
continue;
@ -860,7 +860,7 @@ Aquamarine::CLibinputDevice::~CLibinputDevice() {
}
SP<CLibinputTabletTool> Aquamarine::CLibinputDevice::toolFrom(libinput_tablet_tool* tool) {
for (auto& t : tabletTools) {
for (auto const& t : tabletTools) {
if (t->libinputTool == tool)
return t;
}

View file

@ -168,7 +168,7 @@ bool Aquamarine::CWaylandBackend::dispatchEvents() {
// dispatch frames
if (backend->ready) {
for (auto& f : idleCallbacks) {
for (auto const& f : idleCallbacks) {
f();
}
idleCallbacks.clear();
@ -187,7 +187,7 @@ bool Aquamarine::CWaylandBackend::setCursor(Hyprutils::Memory::CSharedPointer<IB
}
void Aquamarine::CWaylandBackend::onReady() {
for (auto& o : outputs) {
for (auto const& o : outputs) {
o->swapchain = CSwapchain::create(backend->primaryAllocator, self.lock());
if (!o->swapchain) {
backend->log(AQ_LOG_ERROR, std::format("Output {} failed: swapchain creation failed", o->name));
@ -257,7 +257,7 @@ Aquamarine::CWaylandPointer::CWaylandPointer(SP<CCWlPointer> pointer_, Hyprutils
pointer->setEnter([this](CCWlPointer* r, uint32_t serial, wl_proxy* surface, wl_fixed_t x, wl_fixed_t y) {
backend->lastEnterSerial = serial;
for (auto& o : backend->outputs) {
for (auto const& o : backend->outputs) {
if (o->waylandState.surface->resource() != surface)
continue;
@ -269,7 +269,7 @@ Aquamarine::CWaylandPointer::CWaylandPointer(SP<CCWlPointer> pointer_, Hyprutils
});
pointer->setLeave([this](CCWlPointer* r, uint32_t serial, wl_proxy* surface) {
for (auto& o : backend->outputs) {
for (auto const& o : backend->outputs) {
if (o->waylandState.surface->resource() != surface)
continue;
@ -599,7 +599,7 @@ SP<IBackendImplementation> Aquamarine::CWaylandOutput::getBackend() {
SP<CWaylandBuffer> Aquamarine::CWaylandOutput::wlBufferFromBuffer(SP<IBuffer> buffer) {
std::erase_if(backendState.buffers, [this](const auto& el) { return el.first.expired() || !swapchain->contains(el.first.lock()); });
for (auto& [k, v] : backendState.buffers) {
for (auto const& [k, v] : backendState.buffers) {
if (k != buffer)
continue;

View file

@ -153,9 +153,9 @@ static std::vector<SP<CSessionDevice>> scanGPUs(SP<CBackend> backend) {
d = canonicalFilePath.string();
}
for (auto& d : explicitDevices) {
for (auto const& d : explicitDevices) {
bool found = false;
for (auto& vd : devices) {
for (auto const& vd : devices) {
if (vd->path == d) {
vecDevices.emplace_back(vd);
found = true;
@ -169,7 +169,7 @@ static std::vector<SP<CSessionDevice>> scanGPUs(SP<CBackend> backend) {
backend->log(AQ_LOG_ERROR, std::format("drm: Explicit device {} not found", d));
}
} else {
for (auto& d : devices) {
for (auto const& d : devices) {
vecDevices.push_back(d);
}
}
@ -219,7 +219,7 @@ std::vector<SP<CDRMBackend>> Aquamarine::CDRMBackend::attempt(SP<CBackend> backe
std::vector<SP<CDRMBackend>> backends;
SP<CDRMBackend> newPrimary;
for (auto& gpu : gpus) {
for (auto const& gpu : gpus) {
auto drmBackend = SP<CDRMBackend>(new CDRMBackend(backend));
drmBackend->self = drmBackend;
@ -289,7 +289,7 @@ void Aquamarine::CDRMBackend::restoreAfterVT() {
std::vector<SP<SDRMConnector>> noMode;
for (auto& c : connectors) {
for (auto const& c : connectors) {
if (!c->crtc || !c->output)
continue;
@ -342,7 +342,7 @@ void Aquamarine::CDRMBackend::restoreAfterVT() {
backend->log(AQ_LOG_ERROR, std::format("drm: crtc {} failed restore", c->crtc->id));
}
for (auto& c : noMode) {
for (auto const& c : noMode) {
if (!c->output)
continue;
@ -525,7 +525,7 @@ bool Aquamarine::CDRMBackend::initMgpu() {
void Aquamarine::CDRMBackend::buildGlFormats(const std::vector<SGLFormat>& fmts) {
std::vector<SDRMFormat> result;
for (auto& fmt : fmts) {
for (auto const& fmt : fmts) {
if (fmt.external)
continue;
@ -550,7 +550,7 @@ void Aquamarine::CDRMBackend::recheckCRTCs() {
backend->log(AQ_LOG_DEBUG, "drm: Rechecking CRTCs");
std::vector<SP<SDRMConnector>> recheck, changed;
for (auto& c : connectors) {
for (auto const& c : connectors) {
if (c->crtc && c->status == DRM_MODE_CONNECTED) {
backend->log(AQ_LOG_DEBUG, std::format("drm: Skipping connector {}, has crtc {} and is connected", c->szName, c->crtc->id));
continue;
@ -562,7 +562,7 @@ void Aquamarine::CDRMBackend::recheckCRTCs() {
for (size_t i = 0; i < crtcs.size(); ++i) {
bool taken = false;
for (auto& c : connectors) {
for (auto const& c : connectors) {
if (c->crtc != crtcs.at(i))
continue;
@ -580,7 +580,7 @@ void Aquamarine::CDRMBackend::recheckCRTCs() {
bool assigned = false;
// try to use a connected connector
for (auto& c : recheck) {
for (auto const& c : recheck) {
if (!(c->possibleCrtcs & (1 << i)))
continue;
@ -606,7 +606,7 @@ void Aquamarine::CDRMBackend::recheckCRTCs() {
backend->log(AQ_LOG_DEBUG, std::format("drm: slot {} crtc {} unassigned", i, crtcs.at(i)->id));
}
for (auto& c : connectors) {
for (auto const& c : connectors) {
if (c->status == DRM_MODE_CONNECTED)
continue;
@ -615,7 +615,7 @@ void Aquamarine::CDRMBackend::recheckCRTCs() {
// if any connectors get a crtc and are connected, we need to rescan to assign them outputs.
bool rescan = false;
for (auto& c : changed) {
for (auto const& c : changed) {
if (!c->output && c->status == DRM_MODE_CONNECTED) {
rescan = true;
continue;
@ -745,7 +745,7 @@ void Aquamarine::CDRMBackend::scanLeases() {
return;
}
for (auto& c : connectors) {
for (auto const& c : connectors) {
if (!c->output || !c->output->lease)
continue;
@ -767,7 +767,7 @@ void Aquamarine::CDRMBackend::scanLeases() {
auto l = c->output->lease;
for (auto& c2 : connectors) {
for (auto const& c2 : connectors) {
if (!c2->output || c2->output->lease != c->output->lease)
continue;
@ -872,7 +872,7 @@ void Aquamarine::CDRMBackend::onReady() {
}
}
for (auto& c : connectors) {
for (auto const& c : connectors) {
backend->log(AQ_LOG_DEBUG, std::format("drm: onReady: connector {}", c->id));
if (!c->output)
continue;
@ -894,7 +894,7 @@ void Aquamarine::CDRMBackend::onReady() {
}
std::vector<SDRMFormat> Aquamarine::CDRMBackend::getRenderFormats() {
for (auto& p : planes) {
for (auto const& p : planes) {
if (p->type != DRM_PLANE_TYPE_PRIMARY)
continue;
@ -909,7 +909,7 @@ std::vector<SDRMFormat> Aquamarine::CDRMBackend::getRenderableFormats() {
}
std::vector<SDRMFormat> Aquamarine::CDRMBackend::getCursorFormats() {
for (auto& p : planes) {
for (auto const& p : planes) {
if (p->type != DRM_PLANE_TYPE_CURSOR)
continue;
@ -1408,7 +1408,7 @@ bool Aquamarine::CDRMOutput::commitState(bool onlyTest) {
if (COMMITTED & COutputState::eOutputStateProperties::AQ_OUTPUT_STATE_FORMAT) {
// verify the format is valid for the primary plane
bool ok = false;
for (auto& f : getRenderFormats()) {
for (auto const& f : getRenderFormats()) {
if (f.drmFormat == STATE.drmFormat) {
ok = true;
break;
@ -2001,7 +2001,7 @@ SP<CDRMLease> Aquamarine::CDRMLease::create(std::vector<SP<IOutput>> outputs) {
auto backend = ((CDRMBackend*)outputs.at(0)->getBackend().get())->self.lock();
for (auto& o : outputs) {
for (auto const& o : outputs) {
if (o->getBackend() != backend) {
backend->log(AQ_LOG_ERROR, "drm lease: Mismatched backends");
return nullptr;
@ -2012,7 +2012,7 @@ SP<CDRMLease> Aquamarine::CDRMLease::create(std::vector<SP<IOutput>> outputs) {
auto lease = SP<CDRMLease>(new CDRMLease);
for (auto& o : outputs) {
for (auto const& o : outputs) {
auto drmo = ((CDRMOutput*)o.get())->self.lock();
backend->log(AQ_LOG_DEBUG, std::format("drm lease: output {}, connector {}", drmo->name, drmo->connector->id));
@ -2041,7 +2041,7 @@ SP<CDRMLease> Aquamarine::CDRMLease::create(std::vector<SP<IOutput>> outputs) {
return nullptr;
}
for (auto& o : lease->outputs) {
for (auto const& o : lease->outputs) {
o->lease = lease;
}

View file

@ -156,7 +156,7 @@ bool CDRMRenderer::initDRMFormats() {
std::vector<SGLFormat> dmaFormats;
for (auto& fmt : formats) {
for (auto const& fmt : formats) {
std::vector<std::pair<uint64_t, bool>> mods;
auto ret = getModsForFormat(fmt);
@ -170,7 +170,7 @@ bool CDRMRenderer::initDRMFormats() {
// EGL can always do implicit modifiers.
mods.push_back({DRM_FORMAT_MOD_INVALID, true});
for (auto& [mod, external] : mods) {
for (auto const& [mod, external] : mods) {
dmaFormats.push_back(SGLFormat{
.drmFormat = (uint32_t)fmt,
.modifier = mod,
@ -179,7 +179,7 @@ bool CDRMRenderer::initDRMFormats() {
}
TRACE(backend->log(AQ_LOG_TRACE, std::format("EGL: GPU Supports Format {} (0x{:x})", fourccToName((uint32_t)fmt), fmt)));
for (auto& [mod, external] : mods) {
for (auto const& [mod, external] : mods) {
auto modName = drmGetFormatModifierName(mod);
TRACE(backend->log(AQ_LOG_TRACE, std::format("EGL: | {}with modifier 0x{:x}: {}", (external ? "external only " : ""), mod, modName ? modName : "?unknown?")));
free(modName);
@ -455,7 +455,7 @@ SGLTex CDRMRenderer::glTex(Hyprutils::Memory::CSharedPointer<IBuffer> buffa) {
}
bool external = false;
for (auto& fmt : formats) {
for (auto const& fmt : formats) {
if (fmt.drmFormat != dma.format || fmt.modifier != dma.modifier)
continue;
@ -802,7 +802,7 @@ void CDRMRenderer::onBufferAttachmentDrop(CDRMRendererBufferAttachment* attachme
}
bool CDRMRenderer::verifyDestinationDMABUF(const SDMABUFAttrs& attrs) {
for (auto& fmt : formats) {
for (auto const& fmt : formats) {
if (fmt.drmFormat != attrs.format)
continue;

View file

@ -310,16 +310,16 @@ bool Aquamarine::CDRMAtomicImpl::commit(Hyprutils::Memory::CSharedPointer<SDRMCo
bool Aquamarine::CDRMAtomicImpl::reset() {
CDRMAtomicRequest request(backend);
for (auto& crtc : backend->crtcs) {
for (auto const& crtc : backend->crtcs) {
request.add(crtc->id, crtc->props.mode_id, 0);
request.add(crtc->id, crtc->props.active, 0);
}
for (auto& conn : backend->connectors) {
for (auto const& conn : backend->connectors) {
request.add(conn->id, conn->props.crtc_id, 0);
}
for (auto& plane : backend->planes) {
for (auto const& plane : backend->planes) {
request.planeProps(plane, nullptr, 0, {});
}

View file

@ -153,7 +153,7 @@ bool Aquamarine::CDRMLegacyImpl::commit(Hyprutils::Memory::CSharedPointer<SDRMCo
bool Aquamarine::CDRMLegacyImpl::reset() {
bool ok = true;
for (auto& connector : backend->connectors) {
for (auto const& connector : backend->connectors) {
if (!connector->crtc)
continue;

View file

@ -5,7 +5,7 @@ using namespace Hyprutils::Memory;
#define SP CSharedPointer
bool Aquamarine::CAttachmentManager::has(eAttachmentType type) {
for (auto& a : attachments) {
for (auto const& a : attachments) {
if (a->type() == type)
return true;
}
@ -13,7 +13,7 @@ bool Aquamarine::CAttachmentManager::has(eAttachmentType type) {
}
SP<IAttachment> Aquamarine::CAttachmentManager::get(eAttachmentType type) {
for (auto& a : attachments) {
for (auto const& a : attachments) {
if (a->type() == type)
return a;
}

View file

@ -3,7 +3,7 @@
using namespace Aquamarine;
Hyprutils::Memory::CSharedPointer<SOutputMode> Aquamarine::IOutput::preferredMode() {
for (auto& m : modes) {
for (auto const& m : modes) {
if (m->preferred)
return m;
}