Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1197)

Unified Diff: device/serial/serial_device_enumerator_win.cc

Issue 2603893002: Remove mojo::Map. (Closed)
Patch Set: rebase Created 3 years, 12 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « device/serial/serial_device_enumerator_mac.cc ('k') | mojo/public/cpp/bindings/BUILD.gn » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: device/serial/serial_device_enumerator_win.cc
diff --git a/device/serial/serial_device_enumerator_win.cc b/device/serial/serial_device_enumerator_win.cc
index 149331d96c483551066e51190c4a15d5728905c3..aee8e3698fa92adb0d14c1d2eba7d116a5e7e55a 100644
--- a/device/serial/serial_device_enumerator_win.cc
+++ b/device/serial/serial_device_enumerator_win.cc
@@ -10,6 +10,7 @@
#include <windows.h>
#include <memory>
+#include <unordered_set>
#include "base/metrics/histogram_macros.h"
#include "base/strings/string_number_conversions.h"
@@ -164,30 +165,27 @@ SerialDeviceEnumeratorWin::SerialDeviceEnumeratorWin() {}
SerialDeviceEnumeratorWin::~SerialDeviceEnumeratorWin() {}
mojo::Array<serial::DeviceInfoPtr> SerialDeviceEnumeratorWin::GetDevices() {
- mojo::Array<serial::DeviceInfoPtr> newDevices = GetDevicesNew();
- mojo::Array<serial::DeviceInfoPtr> oldDevices = GetDevicesOld();
+ mojo::Array<serial::DeviceInfoPtr> devices = GetDevicesNew();
+ mojo::Array<serial::DeviceInfoPtr> old_devices = GetDevicesOld();
UMA_HISTOGRAM_SPARSE_SLOWLY(
"Hardware.Serial.NewMinusOldDeviceListSize",
- Clamp((int)newDevices.size() - (int)oldDevices.size(), -10, 10));
+ Clamp(devices.size() - old_devices.size(), -10, 10));
// Add devices found from both the new and old methods of enumeration. If a
// device is found using both the new and the old enumeration method, then we
// take the device from the new enumeration method because it's able to
// collect more information. We do this by inserting the new devices first,
// because insertions are ignored if the key already exists.
- mojo::Map<mojo::String, serial::DeviceInfoPtr> deviceMap;
- for (unsigned long i = 0; i < newDevices.size(); i++) {
- deviceMap.insert(newDevices[i]->path, newDevices[i].Clone());
+ std::unordered_set<std::string> devices_seen;
+ for (const auto& device : devices) {
+ bool inserted = devices_seen.insert(device->path).second;
+ DCHECK(inserted);
}
- for (unsigned long i = 0; i < oldDevices.size(); i++) {
- deviceMap.insert(oldDevices[i]->path, oldDevices[i].Clone());
+ for (auto& device : old_devices) {
+ if (devices_seen.insert(device->path).second)
+ devices.push_back(std::move(device));
}
-
- mojo::Array<mojo::String> paths;
- mojo::Array<serial::DeviceInfoPtr> devices;
- deviceMap.DecomposeMapTo(&paths, &devices);
-
return devices;
}
« no previous file with comments | « device/serial/serial_device_enumerator_mac.cc ('k') | mojo/public/cpp/bindings/BUILD.gn » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698