xwayland/selection_source: reduce atomic refcount inc/decrement

This commit is contained in:
Fushan Wen 2024-09-09 21:43:18 +08:00
parent e5c22cefba
commit ed16a957d3
No known key found for this signature in database
GPG key ID: 2E48D1487C91DCAA

View file

@ -18,6 +18,7 @@
#include "wayland_server.h" #include "wayland_server.h"
#include <fcntl.h> #include <fcntl.h>
#include <span>
#include <unistd.h> #include <unistd.h>
#include <xwayland_logging.h> #include <xwayland_logging.h>
@ -213,35 +214,35 @@ void X11Source::handleTargets()
Mimes all; Mimes all;
xcb_atom_t *value = static_cast<xcb_atom_t *>(xcb_get_property_value(reply)); xcb_atom_t *value = static_cast<xcb_atom_t *>(xcb_get_property_value(reply));
for (uint32_t i = 0; i < reply->value_len; i++) { for (xcb_atom_t value : std::span(value, reply->value_len)) {
if (value[i] == XCB_ATOM_NONE) { if (value == XCB_ATOM_NONE) {
continue; continue;
} }
const auto mimeStrings = Selection::atomToMimeTypes(value[i]); const auto mimeStrings = Selection::atomToMimeTypes(value);
if (mimeStrings.isEmpty()) { if (mimeStrings.isEmpty()) {
// TODO: this should never happen? assert? // TODO: this should never happen? assert?
continue; continue;
} }
const auto mimeIt = std::find_if(m_offers.begin(), m_offers.end(), const auto mimeIt = std::find_if(m_offers.begin(), m_offers.end(),
[value, i](const Mime &mime) { [value](const Mime &mime) {
return mime.second == value[i]; return mime.second == value;
}); });
auto mimePair = Mime(mimeStrings[0], value[i]); auto mimePair = Mime(mimeStrings[0], value);
if (mimeIt == m_offers.end()) { if (mimeIt == m_offers.end()) {
added << mimePair.first; added << mimePair.first;
} else { } else {
m_offers.removeAll(mimePair); m_offers.removeAll(mimePair);
} }
all << mimePair; all << std::move(mimePair);
} }
// all left in m_offers are not in the updated targets // all left in m_offers are not in the updated targets
for (const auto &mimePair : std::as_const(m_offers)) { for (const auto &mimePair : std::as_const(m_offers)) {
removed << mimePair.first; removed << mimePair.first;
} }
m_offers = all; m_offers = std::move(all);
if (!added.isEmpty() || !removed.isEmpty()) { if (!added.isEmpty() || !removed.isEmpty()) {
Q_EMIT offersChanged(added, removed); Q_EMIT offersChanged(added, removed);