Commit 2b91ba73 authored by Darwin Huang's avatar Darwin Huang Committed by Commit Bot

ui: Prefer emplace over insert.

Avoid potential unnecessary copies by using emplace consistently.

No intended functional changes.

Bug: 995605
Change-Id: I4e937338a05e6f7322d2813f2f633f0037cd4b67
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1761649Reviewed-by: default avatarScott Violet <sky@chromium.org>
Commit-Queue: Darwin Huang <huangdarwin@chromium.org>
Cr-Commit-Position: refs/heads/master@{#688612}
parent 1db2ac29
......@@ -306,10 +306,10 @@ TEST_F(InputMethodUtilTest, TestGetInputMethodDescriptorFromId) {
TEST_F(InputMethodUtilTest, TestGetInputMethodIdsForLanguageCode) {
std::multimap<std::string, std::string> language_code_to_ids_map;
language_code_to_ids_map.insert(std::make_pair("ja", pinyin_ime_id));
language_code_to_ids_map.insert(std::make_pair("ja", pinyin_ime_id));
language_code_to_ids_map.insert(std::make_pair("ja", "xkb:jp:jpn"));
language_code_to_ids_map.insert(std::make_pair("fr", "xkb:fr:fra"));
language_code_to_ids_map.emplace("ja", pinyin_ime_id);
language_code_to_ids_map.emplace("ja", pinyin_ime_id);
language_code_to_ids_map.emplace("ja", "xkb:jp:jpn");
language_code_to_ids_map.emplace("fr", "xkb:fr:fra");
std::vector<std::string> result;
EXPECT_TRUE(util_.GetInputMethodIdsFromLanguageCodeInternal(
......
......@@ -486,11 +486,11 @@ bool DataPack::WritePack(const base::FilePath& path,
auto it = rev_map.find(entry.second);
if (it != rev_map.end()) {
// Found an alias here!
aliases.insert(std::make_pair(entry.first, it->second));
aliases.emplace(entry.first, it->second);
} else {
// Found a final resource.
const auto entry_index = static_cast<uint16_t>(resource_ids.size());
rev_map.insert(std::make_pair(entry.second, entry_index));
rev_map.emplace(entry.second, entry_index);
resource_ids.push_back(entry.first);
}
}
......
......@@ -216,11 +216,11 @@ TEST_P(DataPackTest, Write) {
std::string fifteen("fifteen");
std::map<uint16_t, base::StringPiece> resources;
resources.insert(std::make_pair(1, base::StringPiece(one)));
resources.insert(std::make_pair(2, base::StringPiece(two)));
resources.insert(std::make_pair(15, base::StringPiece(fifteen)));
resources.insert(std::make_pair(3, base::StringPiece(three)));
resources.insert(std::make_pair(4, base::StringPiece(four)));
resources.emplace(1, base::StringPiece(one));
resources.emplace(2, base::StringPiece(two));
resources.emplace(15, base::StringPiece(fifteen));
resources.emplace(3, base::StringPiece(three));
resources.emplace(4, base::StringPiece(four));
ASSERT_TRUE(DataPack::WritePack(file, resources, GetParam()));
// Now try to read the data back in.
......@@ -256,13 +256,13 @@ TEST_P(DataPackTest, WriteWithAliases) {
std::string fifteen("fifteen");
std::map<uint16_t, base::StringPiece> resources;
resources.insert(std::make_pair(1, base::StringPiece(one)));
resources.insert(std::make_pair(2, base::StringPiece(two)));
resources.insert(std::make_pair(15, base::StringPiece(fifteen)));
resources.insert(std::make_pair(3, base::StringPiece(three)));
resources.insert(std::make_pair(4, base::StringPiece(four)));
resources.insert(std::make_pair(10, base::StringPiece(one)));
resources.insert(std::make_pair(11, base::StringPiece(three)));
resources.emplace(1, base::StringPiece(one));
resources.emplace(2, base::StringPiece(two));
resources.emplace(15, base::StringPiece(fifteen));
resources.emplace(3, base::StringPiece(three));
resources.emplace(4, base::StringPiece(four));
resources.emplace(10, base::StringPiece(one));
resources.emplace(11, base::StringPiece(three));
ASSERT_TRUE(DataPack::WritePack(file, resources, GetParam()));
// Now try to read the data back in.
......
......@@ -563,7 +563,7 @@ gfx::Image& ResourceBundle::GetImageNamed(int resource_id) {
}
// The load was successful, so cache the image.
auto inserted = images_.insert(std::make_pair(resource_id, image));
auto inserted = images_.emplace(resource_id, image);
DCHECK(inserted.second);
return inserted.first->second;
}
......@@ -733,14 +733,14 @@ const gfx::FontList& ResourceBundle::GetFontListWithTypefaceAndDelta(
// to the existing entry that the insertion collided with.
const FontKey sized_key(typeface, size_delta, gfx::Font::NORMAL,
gfx::Font::Weight::NORMAL);
auto sized = font_cache_.insert(std::make_pair(sized_key, base_font_list));
auto sized = font_cache_.emplace(sized_key, base_font_list);
if (sized.second)
sized.first->second = base.DeriveWithSizeDelta(size_delta);
if (styled_key == sized_key) {
return sized.first->second;
}
auto styled = font_cache_.insert(std::make_pair(styled_key, base_font_list));
auto styled = font_cache_.emplace(styled_key, base_font_list);
DCHECK(styled.second); // Otherwise font_cache_.find(..) would have found it.
styled.first->second = sized.first->second.Derive(
0, sized.first->second.GetFontStyle() | style, weight);
......
......@@ -167,7 +167,7 @@ gfx::Image& ResourceBundle::GetNativeImageNamed(int resource_id) {
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
auto inserted = images_.insert(std::make_pair(resource_id, image));
auto inserted = images_.emplace(resource_id, image);
DCHECK(inserted.second);
return inserted.first->second;
}
......
......@@ -139,7 +139,7 @@ gfx::Image& ResourceBundle::GetNativeImageNamed(int resource_id) {
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
auto inserted = images_.insert(std::make_pair(resource_id, image));
auto inserted = images_.emplace(resource_id, image);
DCHECK(inserted.second);
return inserted.first->second;
}
......
......@@ -115,7 +115,7 @@ void SelectionFormatMap::Insert(
::Atom atom,
const scoped_refptr<base::RefCountedMemory>& item) {
data_.erase(atom);
data_.insert(std::make_pair(atom, item));
data_.emplace(atom, item);
}
ui::SelectionData SelectionFormatMap::GetFirstOf(
......
......@@ -141,7 +141,7 @@ DisplayLinkMac::DisplayLinkMac(
DPLOG_IF(ERROR, register_error != kCGErrorSuccess)
<< "CGDisplayRegisterReconfigurationCallback: " << register_error;
}
all_display_links.insert(std::make_pair(display_id_, this));
all_display_links.emplace(display_id_, this);
}
DisplayLinkMac::~DisplayLinkMac() {
......
......@@ -162,7 +162,7 @@ class TestScreenWinManager final : public TestScreenWinInitializer {
HWND CreateFakeHwnd(const gfx::Rect& bounds) override {
EXPECT_EQ(screen_win_, nullptr);
hwnd_map_.insert(std::pair<HWND, gfx::Rect>(++hwndLast_, bounds));
hwnd_map_.emplace(++hwndLast_, bounds);
return hwndLast_;
}
......
......@@ -51,7 +51,7 @@ void FilterFactory::LoadFilterParams(
FilterParamMapKey param_key = {FilterType::kOneEuro, predictor_type};
FilterParams param_value = {{OneEuroFilter::kParamMincutoff, mincutoff},
{OneEuroFilter::kParamBeta, beta}};
filter_params_map_.insert(std::make_pair(param_key, param_value));
filter_params_map_.emplace(param_key, param_value);
}
}
}
......
......@@ -345,7 +345,7 @@ void TouchFactory::CacheTouchscreenIds(int device_id) {
});
// Internal displays will have a vid and pid of 0. Ignore them.
if (it != touchscreens.end() && it->vendor_id && it->product_id)
touchscreen_ids_.insert(std::make_pair(it->vendor_id, it->product_id));
touchscreen_ids_.emplace(it->vendor_id, it->product_id);
}
} // namespace ui
......@@ -116,8 +116,7 @@ class TestStateMachineEventRewriterOld : public EventRewriter {
EventType to_type,
EventRewriteStatus to_status) {
RewriteResult r = {to_state, to_type, to_status};
rules_.insert(std::pair<RewriteCase, RewriteResult>(
RewriteCase(from_state, from_type), r));
rules_.emplace(RewriteCase(from_state, from_type), r);
}
EventRewriteStatus RewriteEvent(
const Event& event,
......
......@@ -272,7 +272,7 @@ class ImageStorage : public base::RefCounted<ImageStorage> {
const ImageRep* AddRepresentation(std::unique_ptr<ImageRep> rep) const {
DCHECK(IsOnValidSequence());
Image::RepresentationType type = rep->type();
auto result = representations_.insert(std::make_pair(type, std::move(rep)));
auto result = representations_.emplace(type, std::move(rep));
// insert should not fail (implies that there was already a representation
// of that type in the map).
......
......@@ -530,7 +530,7 @@ class VectorIconCache {
ImageSkia icon_image(std::make_unique<VectorIconSource>(description),
Size(description.dip_size, description.dip_size));
images_.insert(std::make_pair(description, icon_image));
images_.emplace(description, icon_image);
return icon_image;
}
......
......@@ -39,8 +39,8 @@ uint32_t SequentialIDGenerator::GetGeneratedID(uint32_t number) {
return find->second;
int id = GetNextAvailableID();
number_to_id_.insert(std::make_pair(number, id));
id_to_number_.insert(std::make_pair(id, number));
number_to_id_.emplace(number, id);
id_to_number_.emplace(id, number);
return id;
}
......
......@@ -90,8 +90,8 @@ const ShadowDetails& ShadowDetails::Get(int elevation, int corner_radius) {
if (iter != g_shadow_cache.Get().end())
return iter->second;
auto insertion = g_shadow_cache.Get().insert(std::make_pair(
std::make_pair(elevation, corner_radius), ShadowDetails()));
auto insertion = g_shadow_cache.Get().emplace(
std::make_pair(elevation, corner_radius), ShadowDetails());
DCHECK(insertion.second);
ShadowDetails* shadow = &insertion.first->second;
shadow->values = ShadowValue::MakeMdShadowValues(elevation);
......
......@@ -271,7 +271,7 @@ XAtom X11AtomCache::GetAtom(const char* name) const {
return it->second;
XAtom atom = XInternAtom(xdisplay_, name, False);
cached_atoms_.insert(std::make_pair(name, atom));
cached_atoms_.emplace(name, atom);
return atom;
}
......
......@@ -95,9 +95,11 @@ const char* RealEGLApi::eglQueryStringFn(EGLDisplay dpy, EGLint name) {
if (name == EGL_EXTENSIONS) {
auto it = filtered_exts_.find(dpy);
if (it == filtered_exts_.end()) {
it = filtered_exts_.insert(std::make_pair(
dpy, FilterGLExtensionList(EGLApiBase::eglQueryStringFn(dpy, name),
disabled_exts_))).first;
it = filtered_exts_
.emplace(dpy, FilterGLExtensionList(
EGLApiBase::eglQueryStringFn(dpy, name),
disabled_exts_))
.first;
}
return (*it).second.c_str();
}
......
......@@ -54,7 +54,7 @@ void PopupTimersController::StartTimer(const std::string& id,
std::unique_ptr<PopupTimer> timer(new PopupTimer(id, timeout, AsWeakPtr()));
timer->Start();
popup_timers_.insert(std::make_pair(id, std::move(timer)));
popup_timers_.emplace(id, std::move(timer));
}
void PopupTimersController::StartAll() {
......
......@@ -162,7 +162,7 @@ GbmSurfaceFactory::~GbmSurfaceFactory() {
void GbmSurfaceFactory::RegisterSurface(gfx::AcceleratedWidget widget,
GbmSurfaceless* surface) {
DCHECK(thread_checker_.CalledOnValidThread());
widget_to_surface_map_.insert(std::make_pair(widget, surface));
widget_to_surface_map_.emplace(widget, surface);
}
void GbmSurfaceFactory::UnregisterSurface(gfx::AcceleratedWidget widget) {
......
......@@ -230,7 +230,7 @@ HardwareDisplayController* ScreenManager::GetDisplayController(
void ScreenManager::AddWindow(gfx::AcceleratedWidget widget,
std::unique_ptr<DrmWindow> window) {
std::pair<WidgetToWindowMap::iterator, bool> result =
window_map_.insert(std::make_pair(widget, std::move(window)));
window_map_.emplace(widget, std::move(window));
DCHECK(result.second) << "Window already added.";
UpdateControllerToWindowMapping();
}
......
......@@ -165,7 +165,7 @@ void ScenicSurfaceFactory::AddSurface(gfx::AcceleratedWidget widget,
base::AutoLock lock(surface_lock_);
DCHECK(!base::Contains(surface_map_, widget));
surface->AssertBelongsToCurrentThread();
surface_map_.insert(std::make_pair(widget, surface));
surface_map_.emplace(widget, surface);
}
void ScenicSurfaceFactory::RemoveSurface(gfx::AcceleratedWidget widget) {
......
......@@ -80,7 +80,7 @@ void WaylandBufferManagerGpu::OnPresentation(
void WaylandBufferManagerGpu::RegisterSurface(gfx::AcceleratedWidget widget,
WaylandSurfaceGpu* surface) {
widget_to_surface_map_.insert(std::make_pair(widget, surface));
widget_to_surface_map_.emplace(widget, surface);
}
void WaylandBufferManagerGpu::UnregisterSurface(gfx::AcceleratedWidget widget) {
......
......@@ -99,8 +99,8 @@ class WaylandBufferManagerHost::Surface {
}
bool CreateBuffer(const gfx::Size& size, uint32_t buffer_id) {
auto result = buffers_.insert(std::make_pair(
buffer_id, std::make_unique<WaylandBuffer>(size, buffer_id)));
auto result = buffers_.emplace(
buffer_id, std::make_unique<WaylandBuffer>(size, buffer_id));
return result.second;
}
......
......@@ -74,7 +74,7 @@ void WaylandZwpLinuxDmabuf::CreateBuffer(base::ScopedFD fd,
} else {
// Store the |params| with the corresponding |callback| to identify newly
// created buffer and notify the client about it via the |callback|.
pending_params_.insert(std::make_pair(params, std::move(callback)));
pending_params_.emplace(params, std::move(callback));
zwp_linux_buffer_params_v1_add_listener(params, &params_listener, this);
zwp_linux_buffer_params_v1_create(params, size.width(), size.height(),
......
......@@ -302,7 +302,7 @@ NativeWidgetMacNSWindowHost::NativeWidgetMacNSWindowHost(NativeWidgetMac* owner)
remote_ns_window_host_binding_(this) {
DCHECK(GetIdToWidgetHostImplMap().find(widget_id_) ==
GetIdToWidgetHostImplMap().end());
GetIdToWidgetHostImplMap().insert(std::make_pair(widget_id_, this));
GetIdToWidgetHostImplMap().emplace(widget_id_, this);
DCHECK(owner);
}
......
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