Browse Source

refactor: use base::NumberToString() (#46152)

base::NumberToString() is slightly more efficient than
absl::StrFormat("%u").

Co-authored-by: trop[bot] <37223003+trop[bot]@users.noreply.github.com>
Co-authored-by: Charles Kerr <[email protected]>
trop[bot] 1 month ago
parent
commit
5cda3d226c

+ 3 - 3
shell/browser/serial/serial_chooser_controller.cc

@@ -9,6 +9,7 @@
 
 #include "base/containers/contains.h"
 #include "base/functional/bind.h"
+#include "base/strings/string_number_conversions.h"
 #include "content/public/browser/web_contents.h"
 #include "device/bluetooth/bluetooth_adapter.h"
 #include "device/bluetooth/bluetooth_adapter_factory.h"
@@ -23,7 +24,6 @@
 #include "shell/common/gin_converters/content_converter.h"
 #include "shell/common/gin_helper/dictionary.h"
 #include "shell/common/gin_helper/promise.h"
-#include "third_party/abseil-cpp/absl/strings/str_format.h"
 #include "ui/base/l10n/l10n_util.h"
 
 namespace gin {
@@ -40,10 +40,10 @@ struct Converter<device::mojom::SerialPortInfoPtr> {
       dict.Set("displayName", *port->display_name);
     }
     if (port->has_vendor_id) {
-      dict.Set("vendorId", absl::StrFormat("%u", port->vendor_id));
+      dict.Set("vendorId", base::NumberToString(port->vendor_id));
     }
     if (port->has_product_id) {
-      dict.Set("productId", absl::StrFormat("%u", port->product_id));
+      dict.Set("productId", base::NumberToString(port->product_id));
     }
     if (port->serial_number && !port->serial_number->empty()) {
       dict.Set("serialNumber", *port->serial_number);

+ 3 - 2
shell/common/gin_converters/serial_port_info_converter.h

@@ -5,6 +5,7 @@
 #ifndef ELECTRON_SHELL_COMMON_GIN_CONVERTERS_SERIAL_PORT_INFO_CONVERTER_H_
 #define ELECTRON_SHELL_COMMON_GIN_CONVERTERS_SERIAL_PORT_INFO_CONVERTER_H_
 
+#include "base/strings/string_number_conversions.h"
 #include "gin/converter.h"
 #include "shell/common/gin_helper/dictionary.h"
 #include "third_party/blink/public/mojom/serial/serial.mojom.h"
@@ -22,9 +23,9 @@ struct Converter<device::mojom::SerialPortInfoPtr> {
     if (port->display_name && !port->display_name->empty())
       dict.Set("displayName", *port->display_name);
     if (port->has_vendor_id)
-      dict.Set("vendorId", absl::StrFormat("%u", port->vendor_id));
+      dict.Set("vendorId", base::NumberToString(port->vendor_id));
     if (port->has_product_id)
-      dict.Set("productId", absl::StrFormat("%u", port->product_id));
+      dict.Set("productId", base::NumberToString(port->product_id));
     if (port->serial_number && !port->serial_number->empty())
       dict.Set("serialNumber", *port->serial_number);
 #if BUILDFLAG(IS_MAC)