Commit 7546d332 authored by thestig's avatar thestig Committed by Commit bot

Use container::back() and container::pop_back() in ui/

Also convert !container.size() to container.empty().

Review-Url: https://codereview.chromium.org/2126433002
Cr-Commit-Position: refs/heads/master@{#405289}
parent 47b22eb9
......@@ -283,7 +283,8 @@ void IMM32Manager::CompleteComposition(HWND window_handle, HIMC imm_context) {
}
}
void IMM32Manager::GetCompositionInfo(HIMC imm_context, LPARAM lparam,
void IMM32Manager::GetCompositionInfo(HIMC imm_context,
LPARAM lparam,
CompositionText* composition) {
// We only care about GCS_COMPATTR, GCS_COMPCLAUSE and GCS_CURSORPOS, and
// convert them into underlines and selection range respectively.
......@@ -319,7 +320,9 @@ void IMM32Manager::GetCompositionInfo(HIMC imm_context, LPARAM lparam,
}
// Set default underlines in case there is no clause information.
if (!composition->underlines.size()) {
if (!composition->underlines.empty())
return;
CompositionUnderline underline;
underline.color = SK_ColorBLACK;
underline.background_color = SK_ColorTRANSPARENT;
......@@ -341,7 +344,6 @@ void IMM32Manager::GetCompositionInfo(HIMC imm_context, LPARAM lparam,
underline.thick = false;
composition->underlines.push_back(underline);
}
}
}
bool IMM32Manager::GetString(HIMC imm_context,
......
......@@ -19,7 +19,7 @@ void SetResult(const base::string16& result, ui::win::OpenFileName* ofn) {
ADD_FAILURE() << "filename buffer insufficient.";
return;
}
if (!result.size()) {
if (result.empty()) {
ofn->GetOPENFILENAME()->lpstrFile[0] = 0;
} else {
// Because the result has embedded nulls, we must memcpy.
......
......@@ -24,7 +24,7 @@ LayerAnimatorCollection::~LayerAnimatorCollection() {
void LayerAnimatorCollection::StartAnimator(
scoped_refptr<LayerAnimator> animator) {
DCHECK_EQ(0U, animators_.count(animator));
if (!animators_.size())
if (animators_.empty())
last_tick_time_ = base::TimeTicks::Now();
animators_.insert(animator);
if (animators_.size() == 1U && compositor_)
......
......@@ -262,10 +262,8 @@ class ScreenMac : public Screen {
}
}
if (!displays.size())
return std::vector<Display>(1, GetPrimaryDisplay());
return displays;
return displays.empty() ? std::vector<Display>(1, GetPrimaryDisplay())
: displays;
}
// The displays currently attached to the device.
......
......@@ -20,8 +20,8 @@ namespace {
std::string FormatLog(const char* fmt, va_list args) {
std::string msg = base::StringPrintV(fmt, args);
if (!msg.empty() && msg[msg.size() - 1] == '\n')
msg.erase(msg.end() - 1, msg.end());
if (!msg.empty() && msg.back() == '\n')
msg.pop_back();
return msg;
}
......
......@@ -14,8 +14,8 @@ namespace {
std::string FormatLog(const char* fmt, va_list args) {
std::string msg = base::StringPrintV(fmt, args);
if (!msg.empty() && msg[msg.size() - 1] == '\n')
msg.erase(msg.end() - 1, msg.end());
if (!msg.empty() && msg.back() == '\n')
msg.pop_back();
return msg;
}
......
......@@ -1078,8 +1078,7 @@ void GesturePropertyProvider::ParseXorgConfFile(const std::string& content) {
// one.
if (is_parsing) {
// Stop parsing the current line if the format is wrong.
if (piece.size() <= 2 || piece[0] != '\"' ||
piece[piece.size() - 1] != '\"') {
if (piece.size() <= 2 || piece[0] != '\"' || piece.back() != '\"') {
LOG(ERROR) << "Error parsing line: " << lines.token();
has_error = true;
if (next_is_section_type)
......
......@@ -295,8 +295,8 @@ TEST_F(NotificationListTest, OldPopupShouldNotBeHidden) {
}
popups.clear();
popups = GetPopups();
EXPECT_EQ(1u, popups.size());
EXPECT_EQ(ids[ids.size() - 1], (*popups.begin())->id());
ASSERT_EQ(1u, popups.size());
EXPECT_EQ(ids.back(), (*popups.begin())->id());
}
TEST_F(NotificationListTest, Priority) {
......
......@@ -96,7 +96,7 @@ void PopupTimersController::OnNotificationUpdated(const std::string& id) {
NotificationList::PopupNotifications popup_notifications =
message_center_->GetPopupNotifications();
if (!popup_notifications.size()) {
if (popup_notifications.empty()) {
CancelAll();
return;
}
......
......@@ -95,7 +95,7 @@ std::unique_ptr<views::Border> MakeSeparatorBorder(int top,
// message next to each other within a single column.
class ItemView : public views::View {
public:
ItemView(const message_center::NotificationItem& item);
explicit ItemView(const message_center::NotificationItem& item);
~ItemView() override;
// Overridden from views::View:
......@@ -435,7 +435,7 @@ void NotificationView::CreateOrUpdateMessageView(
message_view_->SetText(text);
}
message_view_->SetVisible(!notification.items().size());
message_view_->SetVisible(notification.items().empty());
}
base::string16 NotificationView::FormatContextMessage(
......@@ -545,7 +545,7 @@ void NotificationView::CreateOrUpdateProgressBarView(
if (!is_indeterminate)
progress_bar_view_->SetValue(notification.progress() / 100.0);
progress_bar_view_->SetVisible(!notification.items().size());
progress_bar_view_->SetVisible(notification.items().empty());
}
void NotificationView::CreateOrUpdateListItemViews(
......
......@@ -278,7 +278,7 @@ std::vector<GammaRampRGBEntry> ResampleLut(
(lut_in[base_index + 1].b - lut_in[base_index].b) *
remaining / desired_size;
} else {
result[i] = lut_in[lut_in.size() - 1];
result[i] = lut_in.back();
}
}
......@@ -304,8 +304,7 @@ class DrmDevice::PageFlipManager {
}
DrmDevice::PageFlipCallback callback = it->callback;
it->pending_calls -= 1;
it->pending_calls--;
if (it->pending_calls)
return;
......@@ -329,11 +328,11 @@ class DrmDevice::PageFlipManager {
};
struct FindCallback {
FindCallback(uint64_t id) : id(id) {}
explicit FindCallback(uint64_t id) : id(id) {}
bool operator()(const PageFlip& flip) const { return flip.id == id; }
uint64_t id;
const uint64_t id;
};
uint64_t next_id_;
......
......@@ -441,7 +441,7 @@ bool TextfieldModel::CanUndo() {
}
bool TextfieldModel::CanRedo() {
if (!edit_history_.size())
if (edit_history_.empty())
return false;
// There is no redo iff the current edit is the last element in the history.
EditHistory::iterator iter = current_edit_;
......@@ -464,7 +464,7 @@ bool TextfieldModel::Undo() {
if (current_edit_ == edit_history_.begin())
current_edit_ = edit_history_.end();
else
current_edit_--;
--current_edit_;
return old != text() || old_cursor != GetCursorPosition();
}
......@@ -478,7 +478,7 @@ bool TextfieldModel::Redo() {
if (current_edit_ == edit_history_.end())
current_edit_ = edit_history_.begin();
else
current_edit_ ++;
++current_edit_;
base::string16 old = text();
size_t old_cursor = GetCursorPosition();
(*current_edit_)->Redo(this);
......@@ -716,7 +716,7 @@ void TextfieldModel::ClearRedoHistory() {
return;
}
EditHistory::iterator delete_start = current_edit_;
delete_start++;
++delete_start;
STLDeleteContainerPointers(delete_start, edit_history_.end());
edit_history_.erase(delete_start, edit_history_.end());
}
......@@ -789,7 +789,7 @@ bool TextfieldModel::AddOrMergeEditHistory(Edit* edit) {
DCHECK_EQ(1u, edit_history_.size());
current_edit_ = edit_history_.begin();
} else {
current_edit_++;
++current_edit_;
}
return false;
}
......
......@@ -937,8 +937,8 @@ void GridLayout::SizeRowsAndColumns(bool layout, int width, int height,
LayoutElement::CalculateLocationsFromSize(&rows_);
// We now know the preferred height, set it here.
pref->set_height(rows_[rows_.size() - 1]->Location() +
rows_[rows_.size() - 1]->Size() + insets_.height());
pref->set_height(rows_.back()->Location() + rows_.back()->Size() +
insets_.height());
if (layout && height != pref->height()) {
// We're doing a layout, and the height differs from the preferred height,
......
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