core: avoid .at() and use [] operator (#9347)

avoid .at() where it makes sense and use [] operator in loops.
This commit is contained in:
Tom Englund 2025-02-06 12:18:04 +01:00 committed by GitHub
parent 868b2b544a
commit f1e32cd122
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
8 changed files with 25 additions and 25 deletions

View file

@ -1626,17 +1626,17 @@ PHLWINDOW CWindow::getSwallower() {
if (!(*PSWALLOWREGEX).empty())
std::erase_if(candidates, [&](const auto& other) { return !RE2::FullMatch(other->m_szClass, *PSWALLOWREGEX); });
if (candidates.size() <= 0)
if (candidates.size() == 0)
return nullptr;
if (!(*PSWALLOWEXREGEX).empty())
std::erase_if(candidates, [&](const auto& other) { return RE2::FullMatch(other->m_szTitle, *PSWALLOWEXREGEX); });
if (candidates.size() <= 0)
if (candidates.size() == 0)
return nullptr;
if (candidates.size() == 1)
return candidates.at(0);
return candidates[0];
// walk up the focus history and find the last focused
for (auto const& w : g_pCompositor->m_vWindowFocusHistory) {
@ -1648,7 +1648,7 @@ PHLWINDOW CWindow::getSwallower() {
}
// if none are found (??) then just return the first one
return candidates.at(0);
return candidates[0];
}
void CWindow::unsetWindowData(eOverridePriority priority) {

View file

@ -126,14 +126,14 @@ void IKeyboard::setKeymap(const SStringRuleNames& rules) {
updateModifiers(0, 0, modifiersState.locked, modifiersState.group);
}
for (size_t i = 0; i < LEDNAMES.size(); ++i) {
ledIndexes.at(i) = xkb_map_led_get_index(xkbKeymap, LEDNAMES.at(i));
Debug::log(LOG, "xkb: LED index {} (name {}) got index {}", i, LEDNAMES.at(i), ledIndexes.at(i));
for (size_t i = 0; i < std::min(LEDNAMES.size(), ledIndexes.size()); ++i) {
ledIndexes[i] = xkb_map_led_get_index(xkbKeymap, LEDNAMES[i]);
Debug::log(LOG, "xkb: LED index {} (name {}) got index {}", i, LEDNAMES[i], ledIndexes[i]);
}
for (size_t i = 0; i < MODNAMES.size(); ++i) {
modIndexes.at(i) = xkb_map_mod_get_index(xkbKeymap, MODNAMES.at(i));
Debug::log(LOG, "xkb: Mod index {} (name {}) got index {}", i, MODNAMES.at(i), modIndexes.at(i));
for (size_t i = 0; i < std::min(MODNAMES.size(), modIndexes.size()); ++i) {
modIndexes[i] = xkb_map_mod_get_index(xkbKeymap, MODNAMES[i]);
Debug::log(LOG, "xkb: Mod index {} (name {}) got index {}", i, MODNAMES[i], modIndexes[i]);
}
updateKeymapFD();
@ -289,8 +289,8 @@ std::optional<uint32_t> IKeyboard::getLEDs() {
return {};
uint32_t leds = 0;
for (uint32_t i = 0; i < LED_COUNT; ++i) {
if (xkb_state_led_index_is_active(xkbState, ledIndexes.at(i)))
for (uint32_t i = 0; i < std::min((size_t)LED_COUNT, ledIndexes.size()); ++i) {
if (xkb_state_led_index_is_active(xkbState, ledIndexes[i]))
leds |= (1 << i);
}
@ -323,10 +323,10 @@ uint32_t IKeyboard::getModifiers() {
uint32_t modMask = modifiersState.depressed | modifiersState.latched;
uint32_t mods = 0;
for (size_t i = 0; i < modIndexes.size(); ++i) {
if (modIndexes.at(i) == XKB_MOD_INVALID)
if (modIndexes[i] == XKB_MOD_INVALID)
continue;
if (!(modMask & (1 << modIndexes.at(i))))
if (!(modMask & (1 << modIndexes[i])))
continue;
mods |= (1 << i);

View file

@ -1357,7 +1357,7 @@ void CHyprMasterLayout::runOrientationCycle(SLayoutMessageHeader& header, CVarLi
int nextOrPrev = 0;
for (size_t i = 0; i < cycle.size(); ++i) {
if (PWORKSPACEDATA->orientation == cycle.at(i)) {
if (PWORKSPACEDATA->orientation == cycle[i]) {
nextOrPrev = i + direction;
break;
}

View file

@ -475,7 +475,7 @@ SP<Aquamarine::IBuffer> CPointerManager::renderHWCursorBuffer(SP<CPointerManager
if (flipRB) {
for (size_t i = 0; i < shmBuffer.size(); i += 4) {
std::swap(shmBuffer.at(i), shmBuffer.at(i + 2)); // little-endian!!!!!!
std::swap(shmBuffer[i], shmBuffer[i + 2]); // little-endian!!!!!!
}
}
} else {

View file

@ -482,7 +482,7 @@ std::vector<SP<SXCursors>> CXCursorManager::loadStandardCursors(std::string cons
// load the default xcursor shapes that exist in the theme
for (size_t i = 0; i < XCURSOR_STANDARD_NAMES.size(); ++i) {
std::string shape{XCURSOR_STANDARD_NAMES.at(i)};
std::string shape{XCURSOR_STANDARD_NAMES[i]};
auto xImages = XcursorShapeLoadImages(i << 1 /* wtf xcursor? */, name.c_str(), size);
if (!xImages) {

View file

@ -402,14 +402,14 @@ std::optional<std::vector<uint64_t>> CHyprOpenGLImpl::getModsForFormat(EGLint fo
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)
for (size_t i = 0; i < std::min(mods.size(), external.size()); ++i) {
if (external[i]) {
if (mods[i] == DRM_FORMAT_MOD_LINEAR)
linearIsExternal = true;
continue;
}
result.push_back(mods.at(i));
result.push_back(mods[i]);
}
// if the driver doesn't mark linear as external, add it. It's allowed unless the driver says otherwise. (e.g. nvidia)

View file

@ -57,8 +57,8 @@ void CXDataSource::send(const std::string& mime, CFileDescriptor fd) {
mimeAtom = HYPRATOMS["UTF8_STRING"];
else {
for (size_t i = 0; i < mimeTypes.size(); ++i) {
if (mimeTypes.at(i) == mime) {
mimeAtom = mimeAtoms.at(i);
if (mimeTypes[i] == mime) {
mimeAtom = mimeAtoms[i];
break;
}
}

View file

@ -1051,13 +1051,13 @@ void CXWM::readWindowData(SP<CXWaylandSurface> surf) {
};
for (size_t i = 0; i < interestingProps.size(); i++) {
xcb_get_property_cookie_t cookie = xcb_get_property(connection, 0, surf->xID, interestingProps.at(i), XCB_ATOM_ANY, 0, 2048);
xcb_get_property_cookie_t cookie = xcb_get_property(connection, 0, surf->xID, interestingProps[i], XCB_ATOM_ANY, 0, 2048);
xcb_get_property_reply_t* reply = xcb_get_property_reply(connection, cookie, nullptr);
if (!reply) {
Debug::log(ERR, "[xwm] Failed to get window property");
continue;
}
readProp(surf, interestingProps.at(i), reply);
readProp(surf, interestingProps[i], reply);
free(reply);
}
}