Skip to content

Commit

Permalink
misc: make for loops const reference (#66)
Browse files Browse the repository at this point in the history
we all like the dreams and prayers that compilers can optimize things
further with const.
  • Loading branch information
gulafaran committed Aug 27, 2024
1 parent abb3c81 commit 7cc3d31
Show file tree
Hide file tree
Showing 11 changed files with 62 additions and 62 deletions.
10 changes: 5 additions & 5 deletions src/allocator/GBM.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,15 +35,15 @@ 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 */
if (name.contains("30"))
return f;
}

for (auto& f : formats) {
for (auto const& f : formats) {
auto name = fourccToName(f.drmFormat);

/* 8 bpp RGB */
Expand Down Expand Up @@ -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;

Expand Down Expand Up @@ -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);
Expand Down
24 changes: 12 additions & 12 deletions src/backend/Backend.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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) {
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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) {
Expand All @@ -162,7 +162,7 @@ bool Aquamarine::CBackend::start() {
return false;

ready = true;
for (auto& b : implementations) {
for (auto const& b : implementations) {
b->onReady();
}

Expand All @@ -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);
}
Expand All @@ -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;
Expand All @@ -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();
}

Expand Down Expand Up @@ -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)();
}
Expand Down
4 changes: 2 additions & 2 deletions src/backend/Headless.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ void Aquamarine::CHeadlessBackend::dispatchTimers() {
}
}

for (auto& copy : toFire) {
for (auto const& copy : toFire) {
if (copy.what)
copy.what();
}
Expand All @@ -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)
Expand Down
10 changes: 5 additions & 5 deletions src/backend/Session.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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));
}
}
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;

Expand Down Expand Up @@ -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;
}
Expand Down
10 changes: 5 additions & 5 deletions src/backend/Wayland.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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));
Expand Down Expand Up @@ -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;

Expand All @@ -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;

Expand Down Expand Up @@ -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;

Expand Down
Loading

0 comments on commit 7cc3d31

Please sign in to comment.