Commit 28841048 authored by Frederik Gladhorn's avatar Frederik Gladhorn

Use const_iterator

Summary: When trivial, replace iterators with the const version.

Reviewers: #kwin, zzag

Reviewed By: #kwin, zzag

Subscribers: kde-frameworks-devel

Tags: #frameworks

Differential Revision: https://phabricator.kde.org/D23917
parent 858d9255
...@@ -361,12 +361,12 @@ void PlasmaWindow::Private::parentWindowCallback(void *data, org_kde_plasma_wind ...@@ -361,12 +361,12 @@ void PlasmaWindow::Private::parentWindowCallback(void *data, org_kde_plasma_wind
Q_UNUSED(window) Q_UNUSED(window)
Private *p = cast(data); Private *p = cast(data);
const auto windows = p->wm->windows(); const auto windows = p->wm->windows();
auto it = std::find_if(windows.begin(), windows.end(), auto it = std::find_if(windows.constBegin(), windows.constEnd(),
[parent] (const PlasmaWindow *w) { [parent] (const PlasmaWindow *w) {
return *w == parent; return *w == parent;
} }
); );
p->setParentWindow(it != windows.end() ? *it : nullptr); p->setParentWindow(it != windows.constEnd() ? *it : nullptr);
} }
void PlasmaWindow::Private::windowGeometryCallback(void *data, org_kde_plasma_window *window, int32_t x, int32_t y, uint32_t width, uint32_t height) void PlasmaWindow::Private::windowGeometryCallback(void *data, org_kde_plasma_window *window, int32_t x, int32_t y, uint32_t width, uint32_t height)
......
...@@ -556,7 +556,7 @@ void Registry::Private::handleGlobalSync() ...@@ -556,7 +556,7 @@ void Registry::Private::handleGlobalSync()
namespace { namespace {
static Registry::Interface nameToInterface(const char *interface) static Registry::Interface nameToInterface(const char *interface)
{ {
for (auto it = s_interfaces.begin(); it != s_interfaces.end(); ++it) { for (auto it = s_interfaces.constBegin(); it != s_interfaces.constEnd(); ++it) {
if (qstrcmp(interface, it.value().name) == 0) { if (qstrcmp(interface, it.value().name) == 0) {
return it.key(); return it.key();
} }
...@@ -601,12 +601,12 @@ void Registry::Private::handleRemove(uint32_t name) ...@@ -601,12 +601,12 @@ void Registry::Private::handleRemove(uint32_t name)
bool Registry::Private::hasInterface(Registry::Interface interface) const bool Registry::Private::hasInterface(Registry::Interface interface) const
{ {
auto it = std::find_if(m_interfaces.begin(), m_interfaces.end(), auto it = std::find_if(m_interfaces.constBegin(), m_interfaces.constEnd(),
[interface](const InterfaceData &data) { [interface](const InterfaceData &data) {
return data.interface == interface; return data.interface == interface;
} }
); );
return it != m_interfaces.end(); return it != m_interfaces.constEnd();
} }
QVector<Registry::AnnouncedInterface> Registry::Private::interfaces(Interface interface) const QVector<Registry::AnnouncedInterface> Registry::Private::interfaces(Interface interface) const
...@@ -873,10 +873,10 @@ static const wl_interface *wlInterface(Registry::Interface interface) ...@@ -873,10 +873,10 @@ static const wl_interface *wlInterface(Registry::Interface interface)
template <typename T> template <typename T>
T *Registry::Private::bind(Registry::Interface interface, uint32_t name, uint32_t version) const T *Registry::Private::bind(Registry::Interface interface, uint32_t name, uint32_t version) const
{ {
auto it = std::find_if(m_interfaces.begin(), m_interfaces.end(), [=](const InterfaceData &data) { auto it = std::find_if(m_interfaces.constBegin(), m_interfaces.constEnd(), [=](const InterfaceData &data) {
return data.interface == interface && data.name == name && data.version >= version; return data.interface == interface && data.name == name && data.version >= version;
}); });
if (it == m_interfaces.end()) { if (it == m_interfaces.constEnd()) {
qCDebug(KWAYLAND_CLIENT) << "Don't have interface " << int(interface) << "with name " << name << "and minimum version" << version; qCDebug(KWAYLAND_CLIENT) << "Don't have interface " << int(interface) << "with name " << name << "and minimum version" << version;
return nullptr; return nullptr;
} }
......
...@@ -61,7 +61,7 @@ void KeyboardInterface::Private::sendEnter(SurfaceInterface *surface, quint32 se ...@@ -61,7 +61,7 @@ void KeyboardInterface::Private::sendEnter(SurfaceInterface *surface, quint32 se
wl_array keys; wl_array keys;
wl_array_init(&keys); wl_array_init(&keys);
const auto states = seat->pressedKeys(); const auto states = seat->pressedKeys();
for (auto it = states.begin(); it != states.end(); ++it) { for (auto it = states.constBegin(); it != states.constEnd(); ++it) {
uint32_t *k = reinterpret_cast<uint32_t*>(wl_array_add(&keys, sizeof(uint32_t))); uint32_t *k = reinterpret_cast<uint32_t*>(wl_array_add(&keys, sizeof(uint32_t)));
*k = *it; *k = *it;
} }
......
...@@ -115,8 +115,8 @@ OutputInterface::Private *OutputInterface::Private::cast(wl_resource *native) ...@@ -115,8 +115,8 @@ OutputInterface::Private *OutputInterface::Private::cast(wl_resource *native)
{ {
for (auto it = s_privates.constBegin(); it != s_privates.constEnd(); ++it) { for (auto it = s_privates.constBegin(); it != s_privates.constEnd(); ++it) {
const auto &resources = (*it)->resources; const auto &resources = (*it)->resources;
auto rit = std::find_if(resources.begin(), resources.end(), [native] (const ResourceData &data) { return data.resource == native; }); auto rit = std::find_if(resources.constBegin(), resources.constEnd(), [native] (const ResourceData &data) { return data.resource == native; });
if (rit != resources.end()) { if (rit != resources.constEnd()) {
return (*it); return (*it);
} }
} }
...@@ -153,12 +153,12 @@ OutputInterface::~OutputInterface() = default; ...@@ -153,12 +153,12 @@ OutputInterface::~OutputInterface() = default;
QSize OutputInterface::pixelSize() const QSize OutputInterface::pixelSize() const
{ {
Q_D(); Q_D();
auto it = std::find_if(d->modes.begin(), d->modes.end(), auto it = std::find_if(d->modes.constBegin(), d->modes.constEnd(),
[](const Mode &mode) { [](const Mode &mode) {
return mode.flags.testFlag(ModeFlag::Current); return mode.flags.testFlag(ModeFlag::Current);
} }
); );
if (it == d->modes.end()) { if (it == d->modes.constEnd()) {
return QSize(); return QSize();
} }
return (*it).size; return (*it).size;
...@@ -167,12 +167,12 @@ QSize OutputInterface::pixelSize() const ...@@ -167,12 +167,12 @@ QSize OutputInterface::pixelSize() const
int OutputInterface::refreshRate() const int OutputInterface::refreshRate() const
{ {
Q_D(); Q_D();
auto it = std::find_if(d->modes.begin(), d->modes.end(), auto it = std::find_if(d->modes.constBegin(), d->modes.constEnd(),
[](const Mode &mode) { [](const Mode &mode) {
return mode.flags.testFlag(ModeFlag::Current); return mode.flags.testFlag(ModeFlag::Current);
} }
); );
if (it == d->modes.end()) { if (it == d->modes.constEnd()) {
return 60000; return 60000;
} }
return (*it).refreshRate; return (*it).refreshRate;
......
...@@ -239,12 +239,12 @@ void OutputDeviceInterface::addMode(Mode &mode) ...@@ -239,12 +239,12 @@ void OutputDeviceInterface::addMode(Mode &mode)
emitChanges(); emitChanges();
return; return;
} else { } else {
auto idIt = std::find_if(d->modes.begin(), d->modes.end(), auto idIt = std::find_if(d->modes.constBegin(), d->modes.constEnd(),
[mode](const Mode &mode_it) { [mode](const Mode &mode_it) {
return mode.id == mode_it.id; return mode.id == mode_it.id;
} }
); );
if (idIt != d->modes.end()) { if (idIt != d->modes.constEnd()) {
qCWarning(KWAYLAND_SERVER) << "Duplicate Mode id" << mode.id << ": not adding mode" << mode.size << mode.refreshRate; qCWarning(KWAYLAND_SERVER) << "Duplicate Mode id" << mode.id << ": not adding mode" << mode.size << mode.refreshRate;
return; return;
} }
......
...@@ -192,7 +192,7 @@ T *interfaceForSurface(SurfaceInterface *surface, const QVector<T*> &interfaces) ...@@ -192,7 +192,7 @@ T *interfaceForSurface(SurfaceInterface *surface, const QVector<T*> &interfaces)
return nullptr; return nullptr;
} }
for (auto it = interfaces.begin(); it != interfaces.end(); ++it) { for (auto it = interfaces.constBegin(); it != interfaces.constEnd(); ++it) {
if ((*it)->client() == surface->client()) { if ((*it)->client() == surface->client()) {
return (*it); return (*it);
} }
...@@ -209,7 +209,7 @@ QVector<T *> interfacesForSurface(SurfaceInterface *surface, const QVector<T*> & ...@@ -209,7 +209,7 @@ QVector<T *> interfacesForSurface(SurfaceInterface *surface, const QVector<T*> &
return ret; return ret;
} }
for (auto it = interfaces.begin(); it != interfaces.end(); ++it) { for (auto it = interfaces.constBegin(); it != interfaces.constEnd(); ++it) {
if ((*it)->client() == surface->client() && (*it)->resource()) { if ((*it)->client() == surface->client() && (*it)->resource()) {
ret << *it; ret << *it;
} }
...@@ -225,7 +225,7 @@ bool forEachInterface(SurfaceInterface *surface, const QVector<T*> &interfaces, ...@@ -225,7 +225,7 @@ bool forEachInterface(SurfaceInterface *surface, const QVector<T*> &interfaces,
return false; return false;
} }
bool calledAtLeastOne = false; bool calledAtLeastOne = false;
for (auto it = interfaces.begin(); it != interfaces.end(); ++it) { for (auto it = interfaces.constBegin(); it != interfaces.constEnd(); ++it) {
if ((*it)->client() == surface->client() && (*it)->resource()) { if ((*it)->client() == surface->client() && (*it)->resource()) {
method(*it); method(*it);
calledAtLeastOne = true; calledAtLeastOne = true;
...@@ -1271,7 +1271,7 @@ QVector< quint32 > SeatInterface::pressedKeys() const ...@@ -1271,7 +1271,7 @@ QVector< quint32 > SeatInterface::pressedKeys() const
{ {
Q_D(); Q_D();
QVector<quint32> keys; QVector<quint32> keys;
for (auto it = d->keys.states.begin(); it != d->keys.states.end(); ++it) { for (auto it = d->keys.states.constBegin(); it != d->keys.states.constEnd(); ++it) {
if (it.value() == Private::Keyboard::State::Pressed) { if (it.value() == Private::Keyboard::State::Pressed) {
keys << it.key(); keys << it.key();
} }
...@@ -1502,7 +1502,7 @@ bool SeatInterface::hasImplicitPointerGrab(quint32 serial) const ...@@ -1502,7 +1502,7 @@ bool SeatInterface::hasImplicitPointerGrab(quint32 serial) const
{ {
Q_D(); Q_D();
const auto &serials = d->globalPointer.buttonSerials; const auto &serials = d->globalPointer.buttonSerials;
for (auto it = serials.begin(), end = serials.end(); it != end; it++) { for (auto it = serials.constBegin(), end = serials.constEnd(); it != end; it++) {
if (it.value() == serial) { if (it.value() == serial) {
return isPointerButtonPressed(it.key()); return isPointerButtonPressed(it.key());
} }
......
...@@ -149,11 +149,11 @@ void PasteClient::setupRegistry(Registry *registry) ...@@ -149,11 +149,11 @@ void PasteClient::setupRegistry(Registry *registry)
return; return;
} }
const auto &mimeTypes = dataOffer->offeredMimeTypes(); const auto &mimeTypes = dataOffer->offeredMimeTypes();
auto it = std::find_if(mimeTypes.begin(), mimeTypes.end(), auto it = std::find_if(mimeTypes.constBegin(), mimeTypes.constEnd(),
[](const QMimeType &type) { [](const QMimeType &type) {
return type.inherits(QStringLiteral("text/plain")); return type.inherits(QStringLiteral("text/plain"));
}); });
if (it == mimeTypes.end()) { if (it == mimeTypes.constEnd()) {
return; return;
} }
int pipeFds[2]; int pipeFds[2];
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment