Use empty() instead of comparing size() with 0

Recommendation from Clang-Tidy: https://clang.llvm.org/extra/clang-tidy/checks/readability-container-size-empty.html
This commit is contained in:
scribam 2019-06-01 15:25:33 +02:00 committed by Ivan
parent bf557ea6e6
commit 09c9996f31
23 changed files with 33 additions and 33 deletions

View File

@ -640,7 +640,7 @@ void logs::file_listener::log(u64 stamp, const logs::message& msg, const std::st
const u64 frac = (stamp % 1'000'000);
fmt::append(text, "%u:%02u:%02u.%06u ", hours, mins, secs, frac);
if (prefix.size() > 0)
if (!prefix.empty())
{
text += "{";
text += prefix;

View File

@ -173,7 +173,7 @@ s32 cellMouseGetData(u32 port_no, vm::ptr<CellMouseData> data)
MouseDataList& data_list = handler->GetDataList(port_no);
if (data_list.size() == 0)
if (data_list.empty())
{
*data = {};
return CELL_OK;

View File

@ -184,7 +184,7 @@ vm::ptr<void> sys_mempool_allocate_block(ppu_thread& ppu, sys_mempool_t mempool)
}
sys_mutex_lock(ppu, memory_pool->mutexid, 0);
while (memory_pool->free_blocks.size() == 0) // while is to guard against spurious wakeups
while (memory_pool->free_blocks.empty()) // while is to guard against spurious wakeups
{
sys_cond_wait(ppu, memory_pool->condid, 0);
memory_pool = idm::get<memory_pool_t>(mempool);
@ -206,7 +206,7 @@ vm::ptr<void> sys_mempool_try_allocate_block(ppu_thread& ppu, sys_mempool_t memp
auto memory_pool = idm::get<memory_pool_t>(mempool);
if (!memory_pool || memory_pool->free_blocks.size() == 0)
if (!memory_pool || memory_pool->free_blocks.empty())
{
return vm::null;
}

View File

@ -39,7 +39,7 @@ error_code sys_tty_read(s32 ch, vm::ptr<char> buf, u32 len, vm::ptr<u32> preadle
{
std::lock_guard lock(g_tty_mutex);
if (g_tty_input[ch].size() > 0)
if (!g_tty_input[ch].empty())
{
// reference to our first queue element
std::string& input = g_tty_input[ch].front();
@ -62,7 +62,7 @@ error_code sys_tty_read(s32 ch, vm::ptr<char> buf, u32 len, vm::ptr<u32> preadle
// remove the just read text from the input string
input = input.substr(chars_to_read, input.size() - 1);
if (input.size() == 0)
if (input.empty())
{
// pop the first queue element if it was completely consumed
g_tty_input[ch].pop_front();

View File

@ -15,7 +15,7 @@ namespace rsx
{
void insert_mem_block_in_map(std::unordered_set<u64>& mem_changes, frame_capture_data::memory_block&& block, frame_capture_data::memory_block_data&& data)
{
if (data.data.size() > 0)
if (!data.data.empty())
{
u64 data_hash = XXH64(data.data.data(), data.data.size(), 0);
block.data_state = data_hash;

View File

@ -65,7 +65,7 @@ namespace rsx
u32 currentOffset = 0x10000000;
for (const auto& rc : frame->replay_commands)
{
bool hasState = (rc.memory_state.size() > 0) || (rc.display_buffer_state != 0) || (rc.tile_state != 0);
bool hasState = (!rc.memory_state.empty()) || (rc.display_buffer_state != 0) || (rc.tile_state != 0);
if (hasState)
{
if (count != 0)
@ -197,7 +197,7 @@ namespace rsx
break;
// Loop and hunt down our next state change that needs to be done
if (!((replay_cmd.memory_state.size() > 0) || (replay_cmd.display_buffer_state != 0) || (replay_cmd.tile_state != 0)))
if (!(!replay_cmd.memory_state.empty() || (replay_cmd.display_buffer_state != 0) || (replay_cmd.tile_state != 0)))
continue;
// wait until rsx idle and at our first 'stop' to apply state

View File

@ -304,7 +304,7 @@ public:
bool is_empty() const
{
return db.size() == 0;
return db.empty();
}
}
patch_table;

View File

@ -200,7 +200,7 @@ public:
auto var_blocks = fmt::split(simple_var, { "." });
verify(HERE), (var_blocks.size() != 0);
verify(HERE), (!var_blocks.empty());
name = prefix + var_blocks[0];

View File

@ -436,7 +436,7 @@ void GLGSRender::end()
clear_depth = true;
}
if (clear_depth || buffers_to_clear.size() > 0)
if (clear_depth || !buffers_to_clear.empty())
{
gl_state.enable(GL_FALSE, GL_SCISSOR_TEST);
GLenum mask = 0;
@ -454,7 +454,7 @@ void GLGSRender::end()
glClear(mask);
if (buffers_to_clear.size() > 0 && !clear_all_color)
if (!buffers_to_clear.empty() && !clear_all_color)
{
GLfloat colors[] = { 0.f, 0.f, 0.f, 0.f };
//It is impossible for the render target to be type A or B here (clear all would have been flagged)

View File

@ -604,7 +604,7 @@ namespace rsx
u16 clip_width = clip_text ? w : UINT16_MAX;
std::vector<vertex> result = renderer->render_text(string, clip_width, wrap_text);
if (result.size() > 0)
if (!result.empty())
{
for (auto &v : result)
{
@ -702,7 +702,7 @@ namespace rsx
cmd_text.config.color = fore_color;
cmd_text.verts = render_text(text.c_str(), (f32)x, (f32)y);
if (cmd_text.verts.size() > 0)
if (!cmd_text.verts.empty())
compiled_resources.add(std::move(compiled_resources_temp), margin_left, margin_top);
}

View File

@ -424,7 +424,7 @@ namespace rsx
void on_draw();
// Check for pending writes
bool has_pending() const { return (m_pending_writes.size() != 0); }
bool has_pending() const { return !m_pending_writes.empty(); }
// Backend methods (optional, will return everything as always visible by default)
virtual void begin_occlusion_query(occlusion_query_info* /*query*/) {}

View File

@ -394,7 +394,7 @@ VKGSRender::VKGSRender() : GSRender()
//Actually confirm that the loader found at least one compatible device
//This should not happen unless something is wrong with the driver setup on the target system
if (gpus.size() == 0)
if (gpus.empty())
{
//We can't throw in Emulator::Load, so we show error and return
LOG_FATAL(RSX, "No compatible GPU devices found");
@ -2167,7 +2167,7 @@ void VKGSRender::clear_surface(u32 mask)
}
}
if (clear_descriptors.size() > 0)
if (!clear_descriptors.empty())
{
begin_render_pass();
vkCmdClearAttachments(*m_current_command_buffer, (u32)clear_descriptors.size(), clear_descriptors.data(), 1, &region);
@ -3538,7 +3538,7 @@ bool VKGSRender::check_occlusion_query_status(rsx::reports::occlusion_query_info
return true;
auto &data = found->second;
if (data.indices.size() == 0)
if (data.indices.empty())
return true;
if (data.command_buffer_to_wait == m_current_command_buffer)
@ -3568,7 +3568,7 @@ void VKGSRender::get_occlusion_query_result(rsx::reports::occlusion_query_info*
return;
auto &data = found->second;
if (data.indices.size() == 0)
if (data.indices.empty())
return;
if (query->num_draws)
@ -3618,7 +3618,7 @@ void VKGSRender::discard_occlusion_query(rsx::reports::occlusion_query_info* que
return;
auto &data = found->second;
if (data.indices.size() == 0)
if (data.indices.empty())
return;
m_occlusion_query_pool.reset_queries(*m_current_command_buffer, data.indices);

View File

@ -95,7 +95,7 @@ bool ds3_pad_handler::Init()
LOG_ERROR(HLE, "[DS3] Check https://wiki.rpcs3.net/index.php?title=Help:Controller_Configuration for intructions on how to solve this issue");
#endif
}
else if (controllers.size() == 0)
else if (controllers.empty())
{
LOG_WARNING(HLE, "[DS3] No controllers found!");
}

View File

@ -209,7 +209,7 @@ void ds4_pad_handler::GetNextButtonPress(const std::string& padId, const std::fu
if (get_blacklist)
{
if (blacklist.size() <= 0)
if (blacklist.empty())
LOG_SUCCESS(HLE, "DS4 Calibration: Blacklist is clear. No input spam detected");
return;
}
@ -786,7 +786,7 @@ bool ds4_pad_handler::Init()
LOG_ERROR(HLE, "[DS4] Check https://wiki.rpcs3.net/index.php?title=Help:Controller_Configuration for intructions on how to solve this issue");
#endif
}
else if (controllers.size() == 0)
else if (controllers.empty())
{
LOG_WARNING(HLE, "[DS4] No controllers found!");
}

View File

@ -364,7 +364,7 @@ void evdev_joystick_handler::GetNextButtonPress(const std::string& padId, const
if (get_blacklist)
{
if (blacklist.size() <= 0)
if (blacklist.empty())
LOG_SUCCESS(HLE, "Evdev Calibration: Blacklist is clear. No input spam detected");
return;
}

View File

@ -391,7 +391,7 @@ void mm_joystick_handler::GetNextButtonPress(const std::string& padId, const std
if (get_blacklist)
{
if (blacklist.size() <= 0)
if (blacklist.empty())
LOG_SUCCESS(HLE, "MMJOY Calibration: Blacklist is clear. No input spam detected");
return;
}

View File

@ -155,7 +155,7 @@ emu_settings::Render_Creator::Render_Creator()
device_enum_context.makeCurrentInstance(instance_handle);
std::vector<vk::physical_device>& gpus = device_enum_context.enumerateDevices();
if (gpus.size() > 0)
if (!gpus.empty())
{
//A device with vulkan support found. Init data
supportsVulkan = true;

View File

@ -57,7 +57,7 @@ struct gui_listener : logs::listener
packet_t p,* _new = &p;
_new->sev = msg.sev;
if (prefix.size() > 0)
if (!prefix.empty())
{
_new->msg += "{";
_new->msg += prefix;

View File

@ -73,7 +73,7 @@ void save_data_info_dialog::UpdateData()
m_list->setItem(3, 1, new QTableWidgetItem(qstr(m_entry.details)));
QImage img;
if (m_entry.iconBuf.size() > 0 && img.loadFromData((uchar*)&m_entry.iconBuf[0], m_entry.iconBuf.size(), "PNG"))
if (!m_entry.iconBuf.empty() && img.loadFromData((uchar*)&m_entry.iconBuf[0], m_entry.iconBuf.size(), "PNG"))
{
m_list->insertRow(0);
QTableWidgetItem* img_item = new QTableWidgetItem();

View File

@ -46,7 +46,7 @@ save_data_list_dialog::save_data_list_dialog(const std::vector<SaveDataEntry>& e
// Button Layout
QHBoxLayout* hbox_action = new QHBoxLayout();
if (entries.size() > 0)
if (!entries.empty())
{ // If there are no entries, don't add the selection widget or the selection label to the UI.
QPushButton *push_select = new QPushButton(tr("&Select Entry"), this);
connect(push_select, &QAbstractButton::clicked, this, &save_data_list_dialog::accept);

View File

@ -257,7 +257,7 @@ void save_manager_dialog::OnEntryRemove()
void save_manager_dialog::OnEntriesRemove()
{
QModelIndexList selection(m_list->selectionModel()->selectedRows());
if (selection.size() == 0)
if (selection.empty())
{
return;
}

View File

@ -25,7 +25,7 @@ trophy_notification_frame::trophy_notification_frame(const std::vector<uchar>& i
trophyImgLabel->setPalette(black_background);
QImage trophyImg;
if (imgBuffer.size() > 0 && trophyImg.loadFromData((uchar*)&imgBuffer[0], imgBuffer.size(), "PNG"))
if (!imgBuffer.empty() && trophyImg.loadFromData((uchar*)&imgBuffer[0], imgBuffer.size(), "PNG"))
{
trophyImg = trophyImg.scaledToHeight(height); // I might consider adding ability to change size since on hidpi this will be rather small.
trophyImgLabel->setPixmap(QPixmap::fromImage(trophyImg));

View File

@ -123,7 +123,7 @@ void xinput_pad_handler::GetNextButtonPress(const std::string& padId, const std:
if (get_blacklist)
{
if (blacklist.size() <= 0)
if (blacklist.empty())
LOG_SUCCESS(HLE, "XInput Calibration: Blacklist is clear. No input spam detected");
return;
}