Merge pull request #12399 from lioncash/erasing
General: Make use of std::erase_if/std::erase where applicable
This commit is contained in:
commit
8cbb2c2e44
|
@ -43,9 +43,7 @@ const std::vector<Watch>& Watches::GetWatches() const
|
|||
|
||||
void Watches::UnsetWatch(u32 address)
|
||||
{
|
||||
m_watches.erase(std::remove_if(m_watches.begin(), m_watches.end(),
|
||||
[address](const auto& watch) { return watch.address == address; }),
|
||||
m_watches.end());
|
||||
std::erase_if(m_watches, [address](const auto& watch) { return watch.address == address; });
|
||||
}
|
||||
|
||||
void Watches::UpdateWatch(std::size_t index, u32 address, std::string name)
|
||||
|
|
|
@ -997,13 +997,11 @@ void RunAllActive(const Core::CPUThreadGuard& cpu_guard)
|
|||
// are only atomic ops unless contested. It should be rare for this to
|
||||
// be contested.
|
||||
std::lock_guard guard(s_lock);
|
||||
s_active_codes.erase(std::remove_if(s_active_codes.begin(), s_active_codes.end(),
|
||||
[&cpu_guard](const ARCode& code) {
|
||||
bool success = RunCodeLocked(cpu_guard, code);
|
||||
LogInfo("\n");
|
||||
return !success;
|
||||
}),
|
||||
s_active_codes.end());
|
||||
std::erase_if(s_active_codes, [&cpu_guard](const ARCode& code) {
|
||||
const bool success = RunCodeLocked(cpu_guard, code);
|
||||
LogInfo("\n");
|
||||
return !success;
|
||||
});
|
||||
s_disable_logging = true;
|
||||
}
|
||||
|
||||
|
|
|
@ -138,9 +138,7 @@ std::vector<GeckoCode> LoadCodes(const Common::IniFile& globalIni, const Common:
|
|||
|
||||
GeckoCode gcode;
|
||||
|
||||
lines.erase(std::remove_if(lines.begin(), lines.end(),
|
||||
[](const auto& line) { return line.empty() || line[0] == '#'; }),
|
||||
lines.end());
|
||||
std::erase_if(lines, [](const auto& line) { return line.empty() || line[0] == '#'; });
|
||||
|
||||
for (auto& line : lines)
|
||||
{
|
||||
|
|
|
@ -14,7 +14,7 @@ void I2CBus::AddSlave(I2CSlave* slave)
|
|||
|
||||
void I2CBus::RemoveSlave(I2CSlave* slave)
|
||||
{
|
||||
m_slaves.erase(std::remove(m_slaves.begin(), m_slaves.end(), slave), m_slaves.end());
|
||||
std::erase(m_slaves, slave);
|
||||
}
|
||||
|
||||
void I2CBus::Reset()
|
||||
|
|
|
@ -614,9 +614,7 @@ std::string SharedContentMap::AddSharedContent(const std::array<u8, 20>& sha1)
|
|||
|
||||
bool SharedContentMap::DeleteSharedContent(const std::array<u8, 20>& sha1)
|
||||
{
|
||||
m_entries.erase(std::remove_if(m_entries.begin(), m_entries.end(),
|
||||
[&sha1](const auto& entry) { return entry.sha1 == sha1; }),
|
||||
m_entries.end());
|
||||
std::erase_if(m_entries, [&sha1](const auto& entry) { return entry.sha1 == sha1; });
|
||||
return WriteEntries();
|
||||
}
|
||||
|
||||
|
|
|
@ -556,7 +556,7 @@ NWC24::ErrorCode NetKDRequestDevice::KDSendMail()
|
|||
{
|
||||
LogError(ErrorType::SendMail, res);
|
||||
}
|
||||
mails.erase(std::remove(mails.begin(), mails.end(), file_index), mails.end());
|
||||
std::erase(mails, file_index);
|
||||
continue;
|
||||
}
|
||||
|
||||
|
@ -574,7 +574,7 @@ NWC24::ErrorCode NetKDRequestDevice::KDSendMail()
|
|||
LogError(ErrorType::SendMail, res);
|
||||
}
|
||||
|
||||
mails.erase(std::remove(mails.begin(), mails.end(), file_index), mails.end());
|
||||
std::erase(mails, file_index);
|
||||
continue;
|
||||
}
|
||||
|
||||
|
|
|
@ -1047,66 +1047,61 @@ void WiiSockMan::UpdatePollCommands()
|
|||
auto& system = Core::System::GetInstance();
|
||||
auto& memory = system.GetMemory();
|
||||
|
||||
pending_polls.erase(
|
||||
std::remove_if(
|
||||
pending_polls.begin(), pending_polls.end(),
|
||||
[&system, &memory, this](PollCommand& pcmd) {
|
||||
const auto request = Request(system, pcmd.request_addr);
|
||||
auto& pfds = pcmd.wii_fds;
|
||||
int ret = 0;
|
||||
std::erase_if(pending_polls, [&system, &memory, this](PollCommand& pcmd) {
|
||||
const auto request = Request(system, pcmd.request_addr);
|
||||
auto& pfds = pcmd.wii_fds;
|
||||
int ret = 0;
|
||||
|
||||
// Happens only on savestate load
|
||||
if (pfds[0].revents & error_event)
|
||||
{
|
||||
ret = static_cast<int>(pfds.size());
|
||||
}
|
||||
else
|
||||
{
|
||||
// Make the behavior of poll consistent across platforms by not passing:
|
||||
// - Set with invalid fds, revents is set to 0 (Linux) or POLLNVAL (Windows)
|
||||
// - Set without a valid socket, raises an error on Windows
|
||||
std::vector<int> original_order(pfds.size());
|
||||
std::iota(original_order.begin(), original_order.end(), 0);
|
||||
// Select indices with valid fds
|
||||
auto mid = std::partition(original_order.begin(), original_order.end(), [&](auto i) {
|
||||
return GetHostSocket(memory.Read_U32(pcmd.buffer_out + 0xc * i)) >= 0;
|
||||
});
|
||||
const auto n_valid = std::distance(original_order.begin(), mid);
|
||||
// Happens only on savestate load
|
||||
if (pfds[0].revents & error_event)
|
||||
{
|
||||
ret = static_cast<int>(pfds.size());
|
||||
}
|
||||
else
|
||||
{
|
||||
// Make the behavior of poll consistent across platforms by not passing:
|
||||
// - Set with invalid fds, revents is set to 0 (Linux) or POLLNVAL (Windows)
|
||||
// - Set without a valid socket, raises an error on Windows
|
||||
std::vector<int> original_order(pfds.size());
|
||||
std::iota(original_order.begin(), original_order.end(), 0);
|
||||
// Select indices with valid fds
|
||||
auto mid = std::partition(original_order.begin(), original_order.end(), [&](auto i) {
|
||||
return GetHostSocket(memory.Read_U32(pcmd.buffer_out + 0xc * i)) >= 0;
|
||||
});
|
||||
const auto n_valid = std::distance(original_order.begin(), mid);
|
||||
|
||||
// Move all the valid pollfds to the front of the vector
|
||||
for (auto i = 0; i < n_valid; ++i)
|
||||
std::swap(pfds[i], pfds[original_order[i]]);
|
||||
// Move all the valid pollfds to the front of the vector
|
||||
for (auto i = 0; i < n_valid; ++i)
|
||||
std::swap(pfds[i], pfds[original_order[i]]);
|
||||
|
||||
if (n_valid > 0)
|
||||
ret = poll(pfds.data(), n_valid, 0);
|
||||
if (ret < 0)
|
||||
ret = GetNetErrorCode(ret, "UpdatePollCommands", false);
|
||||
if (n_valid > 0)
|
||||
ret = poll(pfds.data(), n_valid, 0);
|
||||
if (ret < 0)
|
||||
ret = GetNetErrorCode(ret, "UpdatePollCommands", false);
|
||||
|
||||
// Move everything back to where they were
|
||||
for (auto i = 0; i < n_valid; ++i)
|
||||
std::swap(pfds[i], pfds[original_order[i]]);
|
||||
}
|
||||
// Move everything back to where they were
|
||||
for (auto i = 0; i < n_valid; ++i)
|
||||
std::swap(pfds[i], pfds[original_order[i]]);
|
||||
}
|
||||
|
||||
if (ret == 0 && pcmd.timeout)
|
||||
return false;
|
||||
if (ret == 0 && pcmd.timeout)
|
||||
return false;
|
||||
|
||||
// Translate native to Wii events,
|
||||
for (u32 i = 0; i < pfds.size(); ++i)
|
||||
{
|
||||
const int revents = ConvertEvents(pfds[i].revents, ConvertDirection::NativeToWii);
|
||||
// Translate native to Wii events,
|
||||
for (u32 i = 0; i < pfds.size(); ++i)
|
||||
{
|
||||
const int revents = ConvertEvents(pfds[i].revents, ConvertDirection::NativeToWii);
|
||||
|
||||
// No need to change fd or events as they are input only.
|
||||
// memory.Write_U32(ufds[i].fd, request.buffer_out + 0xc*i); //fd
|
||||
// memory.Write_U32(events, request.buffer_out + 0xc*i + 4); //events
|
||||
memory.Write_U32(revents, pcmd.buffer_out + 0xc * i + 8); // revents
|
||||
DEBUG_LOG_FMT(IOS_NET,
|
||||
"IOCTL_SO_POLL socket {} wevents {:08X} events {:08X} revents {:08X}",
|
||||
i, revents, pfds[i].events, pfds[i].revents);
|
||||
}
|
||||
GetIOS()->EnqueueIPCReply(request, ret);
|
||||
return true;
|
||||
}),
|
||||
pending_polls.end());
|
||||
// No need to change fd or events as they are input only.
|
||||
// memory.Write_U32(ufds[i].fd, request.buffer_out + 0xc*i); //fd
|
||||
// memory.Write_U32(events, request.buffer_out + 0xc*i + 4); //events
|
||||
memory.Write_U32(revents, pcmd.buffer_out + 0xc * i + 8); // revents
|
||||
DEBUG_LOG_FMT(IOS_NET, "IOCTL_SO_POLL socket {} wevents {:08X} events {:08X} revents {:08X}",
|
||||
i, revents, pfds[i].events, pfds[i].revents);
|
||||
}
|
||||
GetIOS()->EnqueueIPCReply(request, ret);
|
||||
return true;
|
||||
});
|
||||
}
|
||||
|
||||
void WiiSockMan::ToNativeAddrIn(const u8* addr, sockaddr_in* to)
|
||||
|
|
|
@ -325,8 +325,7 @@ void AddMemoryPatch(std::size_t index)
|
|||
void RemoveMemoryPatch(std::size_t index)
|
||||
{
|
||||
std::lock_guard lock(s_on_frame_memory_mutex);
|
||||
s_on_frame_memory.erase(std::remove(s_on_frame_memory.begin(), s_on_frame_memory.end(), index),
|
||||
s_on_frame_memory.end());
|
||||
std::erase(s_on_frame_memory, index);
|
||||
}
|
||||
|
||||
bool ApplyFramePatches()
|
||||
|
|
|
@ -250,9 +250,7 @@ SysConf::Entry* SysConf::GetOrAddEntry(std::string_view key, Entry::Type type)
|
|||
|
||||
void SysConf::RemoveEntry(std::string_view key)
|
||||
{
|
||||
m_entries.erase(std::remove_if(m_entries.begin(), m_entries.end(),
|
||||
[&key](const auto& entry) { return entry.name == key; }),
|
||||
m_entries.end());
|
||||
std::erase_if(m_entries, [&key](const auto& entry) { return entry.name == key; });
|
||||
}
|
||||
|
||||
void SysConf::InsertDefaultEntries()
|
||||
|
|
|
@ -963,11 +963,9 @@ static ParseResult ParseComplexExpression(const std::string& str)
|
|||
|
||||
void RemoveInertTokens(std::vector<Token>* tokens)
|
||||
{
|
||||
tokens->erase(std::remove_if(tokens->begin(), tokens->end(),
|
||||
[](const Token& tok) {
|
||||
return tok.type == TOK_COMMENT || tok.type == TOK_WHITESPACE;
|
||||
}),
|
||||
tokens->end());
|
||||
std::erase_if(*tokens, [](const Token& tok) {
|
||||
return tok.type == TOK_COMMENT || tok.type == TOK_WHITESPACE;
|
||||
});
|
||||
}
|
||||
|
||||
static std::unique_ptr<Expression> ParseBarewordExpression(const std::string& str)
|
||||
|
|
|
@ -144,8 +144,7 @@ void RemoveSpuriousTriggerCombinations(
|
|||
});
|
||||
};
|
||||
|
||||
detections->erase(std::remove_if(detections->begin(), detections->end(), is_spurious),
|
||||
detections->end());
|
||||
std::erase_if(*detections, is_spurious);
|
||||
}
|
||||
|
||||
} // namespace ciface::MappingCommon
|
||||
|
|
Loading…
Reference in New Issue