Skip to content

Commit c5e96b9

Browse files
committed
Accept std::string_view in CuttlefishConfig::InstanceSpecific::PerInstance*
https://abseil.io/tips/1 Bug: b/470439524
1 parent 5afa65f commit c5e96b9

File tree

3 files changed

+40
-39
lines changed

3 files changed

+40
-39
lines changed

base/cvd/cuttlefish/host/libs/config/BUILD.bazel

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,7 @@ cf_cc_library(
117117
"//cuttlefish/host/libs/config:secure_hals",
118118
"//cuttlefish/host/libs/config:vmm_mode",
119119
"//libbase",
120+
"@abseil-cpp//absl/strings",
120121
"@fmt",
121122
"@jsoncpp",
122123
"@protobuf",

base/cvd/cuttlefish/host/libs/config/cuttlefish_config.h

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,13 @@
2323
#include <optional>
2424
#include <set>
2525
#include <string>
26+
#include <string_view>
2627
#include <vector>
2728

2829
#include "cuttlefish/common/libs/utils/device_type.h"
2930
#include "cuttlefish/common/libs/utils/host_info.h"
3031
#include "cuttlefish/common/libs/utils/result.h"
32+
#include "cuttlefish/host/commands/assemble_cvd/proto/guest_config.pb.h"
3133
#include "cuttlefish/host/libs/config/ap_boot_flow.h"
3234
#include "cuttlefish/host/libs/config/boot_flow.h"
3335
#include "cuttlefish/host/libs/config/config_constants.h"
@@ -39,8 +41,6 @@
3941
#include "cuttlefish/host/libs/config/secure_hals.h"
4042
#include "cuttlefish/host/libs/config/vmm_mode.h"
4143

42-
#include "cuttlefish/host/commands/assemble_cvd/proto/guest_config.pb.h"
43-
4444
namespace Json {
4545
class Value;
4646
}
@@ -325,9 +325,9 @@ class CuttlefishConfig {
325325

326326
// Returns the path to a file with the given name in the instance
327327
// directory..
328-
std::string PerInstancePath(const std::string& file_name) const;
329-
std::string PerInstanceInternalPath(const std::string& file_name) const;
330-
std::string PerInstanceLogPath(const std::string& file_name) const;
328+
std::string PerInstancePath(std::string_view file_name) const;
329+
std::string PerInstanceInternalPath(std::string_view file_name) const;
330+
std::string PerInstanceLogPath(std::string_view file_name) const;
331331

332332
std::string CrosvmSocketPath() const;
333333
std::string OpenwrtCrosvmSocketPath() const;
@@ -338,9 +338,9 @@ class CuttlefishConfig {
338338
// Return the Unix domain socket path with given name. Because the
339339
// length limitation of Unix domain socket name, it needs to be in
340340
// the another directory than normal Instance path.
341-
std::string PerInstanceUdsPath(const std::string& file_name) const;
342-
std::string PerInstanceInternalUdsPath(const std::string& file_name) const;
343-
std::string PerInstanceGrpcSocketPath(const std::string& socket_name) const;
341+
std::string PerInstanceUdsPath(std::string_view file_name) const;
342+
std::string PerInstanceInternalUdsPath(std::string_view file_name) const;
343+
std::string PerInstanceGrpcSocketPath(std::string_view socket_name) const;
344344

345345
std::string instance_uds_dir() const;
346346

base/cvd/cuttlefish/host/libs/config/cuttlefish_config_instance.cpp

Lines changed: 31 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -23,33 +23,33 @@
2323
#include <fstream>
2424
#include <optional>
2525
#include <string>
26+
#include <string_view>
2627
#include <utility>
2728
#include <vector>
2829

29-
#include <android-base/logging.h>
30-
#include <android-base/strings.h>
31-
#include <fmt/core.h>
32-
#include <fmt/format.h>
33-
#include <json/config.h>
34-
#include <json/reader.h>
35-
#include <json/value.h>
36-
37-
#include <google/protobuf/text_format.h>
30+
#include "absl/strings/str_cat.h"
31+
#include "android-base/logging.h"
32+
#include "android-base/strings.h"
33+
#include "fmt/core.h"
34+
#include "fmt/format.h"
35+
#include "google/protobuf/text_format.h"
36+
#include "json/config.h"
37+
#include "json/reader.h"
38+
#include "json/value.h"
3839

3940
#include "cuttlefish/common/libs/utils/device_type.h"
4041
#include "cuttlefish/common/libs/utils/files.h"
4142
#include "cuttlefish/common/libs/utils/flags_validator.h"
4243
#include "cuttlefish/common/libs/utils/host_info.h"
4344
#include "cuttlefish/common/libs/utils/result.h"
45+
#include "cuttlefish/host/commands/assemble_cvd/proto/guest_config.pb.h"
4446
#include "cuttlefish/host/libs/config/ap_boot_flow.h"
4547
#include "cuttlefish/host/libs/config/boot_flow.h"
4648
#include "cuttlefish/host/libs/config/config_constants.h"
4749
#include "cuttlefish/host/libs/config/external_network_mode.h"
4850
#include "cuttlefish/host/libs/config/guest_hwui_renderer.h"
4951
#include "cuttlefish/host/libs/config/guest_renderer_preload.h"
5052

51-
#include "cuttlefish/host/commands/assemble_cvd/proto/guest_config.pb.h"
52-
5353
namespace cuttlefish {
5454
namespace {
5555

@@ -1915,8 +1915,8 @@ bool CuttlefishConfig::InstanceSpecific::enable_tap_devices() const {
19151915

19161916
std::string CuttlefishConfig::InstanceSpecific::touch_socket_path(
19171917
int touch_dev_idx) const {
1918-
return PerInstanceInternalUdsPath(
1919-
("touch_" + std::to_string(touch_dev_idx) + ".sock").c_str());
1918+
std::string name = absl::StrCat("touch_", touch_dev_idx, ".sock");
1919+
return PerInstanceInternalUdsPath(name);
19201920
}
19211921

19221922
std::string CuttlefishConfig::InstanceSpecific::mouse_socket_path() const {
@@ -2004,53 +2004,53 @@ CuttlefishConfig::InstanceSpecific::audio_settings() const {
20042004
}
20052005

20062006
std::string CuttlefishConfig::InstanceSpecific::PerInstancePath(
2007-
const std::string& file_name) const {
2008-
return (instance_dir() + "/") + file_name;
2007+
std::string_view file_name) const {
2008+
return absl::StrCat(instance_dir(), "/", file_name);
20092009
}
20102010

20112011
std::string CuttlefishConfig::InstanceSpecific::PerInstanceInternalPath(
2012-
const std::string& file_name) const {
2013-
if (file_name[0] == '\0') {
2012+
std::string_view file_name) const {
2013+
if (file_name.empty()) {
20142014
// Don't append a / if file_name is empty.
20152015
return PerInstancePath(kInternalDirName);
20162016
}
2017-
auto relative_path = (std::string(kInternalDirName) + "/") + file_name;
2018-
return PerInstancePath(relative_path.c_str());
2017+
std::string relative_path = absl::StrCat(kInternalDirName, "/", file_name);
2018+
return PerInstancePath(relative_path);
20192019
}
20202020

20212021
std::string CuttlefishConfig::InstanceSpecific::PerInstanceUdsPath(
2022-
const std::string& file_name) const {
2023-
return (instance_uds_dir() + "/") + file_name;
2022+
std::string_view file_name) const {
2023+
return absl::StrCat(instance_uds_dir(), "/", file_name);
20242024
}
20252025

20262026
std::string CuttlefishConfig::InstanceSpecific::PerInstanceInternalUdsPath(
2027-
const std::string& file_name) const {
2028-
if (file_name[0] == '\0') {
2027+
std::string_view file_name) const {
2028+
if (file_name.empty()) {
20292029
// Don't append a / if file_name is empty.
20302030
return PerInstanceUdsPath(kInternalDirName);
20312031
}
2032-
auto relative_path = (std::string(kInternalDirName) + "/") + file_name;
2033-
return PerInstanceUdsPath(relative_path.c_str());
2032+
std::string relative_path = absl::StrCat(kInternalDirName, "/", file_name);
2033+
return PerInstanceUdsPath(relative_path);
20342034
}
20352035

20362036
std::string CuttlefishConfig::InstanceSpecific::PerInstanceGrpcSocketPath(
2037-
const std::string& socket_name) const {
2037+
std::string_view socket_name) const {
20382038
if (socket_name.empty()) {
20392039
// Don't append a / if file_name is empty.
20402040
return PerInstanceUdsPath(kGrpcSocketDirName);
20412041
}
2042-
auto relative_path = (std::string(kGrpcSocketDirName) + "/") + socket_name;
2043-
return PerInstanceUdsPath(relative_path.c_str());
2042+
std::string rel_path = absl::StrCat(kGrpcSocketDirName, "/", socket_name);
2043+
return PerInstanceUdsPath(rel_path);
20442044
}
20452045

20462046
std::string CuttlefishConfig::InstanceSpecific::PerInstanceLogPath(
2047-
const std::string& file_name) const {
2047+
std::string_view file_name) const {
20482048
if (file_name.empty()) {
20492049
// Don't append a / if file_name is empty.
20502050
return PerInstancePath(kLogDirName);
20512051
}
2052-
auto relative_path = (std::string(kLogDirName) + "/") + file_name;
2053-
return PerInstancePath(relative_path.c_str());
2052+
std::string relative_path = absl::StrCat(kLogDirName, "/", file_name);
2053+
return PerInstancePath(relative_path);
20542054
}
20552055

20562056
std::string CuttlefishConfig::InstanceSpecific::instance_name() const {

0 commit comments

Comments
 (0)