init: Avoid extra string copies when finding devices by using const refs

Now that FindPlatformDevice() isn't modifying the path argument, and
is just passing it on to FindSubsystemDevice(), take this argument by
const reference. That should avoid an unnecessary string copy.

Bug: 316324155
Test: Compile
Change-Id: I1d92a322d0c311ee46a117dd9d650896ec02520f
This commit is contained in:
Douglas Anderson 2024-11-08 14:38:41 -08:00
parent 244a63066b
commit 46afe22f9d
2 changed files with 7 additions and 6 deletions

View file

@ -307,7 +307,8 @@ bool DeviceHandler::FindSubsystemDevice(std::string path, std::string* device_pa
return false;
}
bool DeviceHandler::FindPlatformDevice(std::string path, std::string* platform_device_path) const {
bool DeviceHandler::FindPlatformDevice(const std::string& path,
std::string* platform_device_path) const {
const std::set<std::string> subsystem_paths = {
sysfs_mount_point_ + "/bus/platform",
sysfs_mount_point_ + "/bus/amba",
@ -316,7 +317,7 @@ bool DeviceHandler::FindPlatformDevice(std::string path, std::string* platform_d
return FindSubsystemDevice(path, platform_device_path, subsystem_paths);
}
bool DeviceHandler::FindMmcDevice(std::string path, std::string* mmc_device_path) const {
bool DeviceHandler::FindMmcDevice(const std::string& path, std::string* mmc_device_path) const {
const std::set<std::string> subsystem_paths = {
sysfs_mount_point_ + "/bus/mmc",
};
@ -324,7 +325,7 @@ bool DeviceHandler::FindMmcDevice(std::string path, std::string* mmc_device_path
return FindSubsystemDevice(path, mmc_device_path, subsystem_paths);
}
bool DeviceHandler::FindScsiDevice(std::string path, std::string* scsi_device_path) const {
bool DeviceHandler::FindScsiDevice(const std::string& path, std::string* scsi_device_path) const {
const std::set<std::string> subsystem_paths = {
sysfs_mount_point_ + "/bus/scsi",
};

View file

@ -149,9 +149,9 @@ class DeviceHandler : public UeventHandler {
BlockDeviceInfo GetBlockDeviceInfo(const std::string& uevent_path) const;
bool FindSubsystemDevice(std::string path, std::string* device_path,
const std::set<std::string>& subsystem_paths) const;
bool FindPlatformDevice(std::string path, std::string* platform_device_path) const;
bool FindMmcDevice(std::string path, std::string* mmc_device_path) const;
bool FindScsiDevice(std::string path, std::string* scsi_device_path) const;
bool FindPlatformDevice(const std::string& path, std::string* platform_device_path) const;
bool FindMmcDevice(const std::string& path, std::string* mmc_device_path) const;
bool FindScsiDevice(const std::string& path, std::string* scsi_device_path) const;
std::tuple<mode_t, uid_t, gid_t> GetDevicePermissions(
const std::string& path, const std::vector<std::string>& links) const;
void MakeDevice(const std::string& path, bool block, int major, int minor,