From 46afe22f9da648487d6e8b7c8a3f35cc15a3412b Mon Sep 17 00:00:00 2001 From: Douglas Anderson Date: Fri, 8 Nov 2024 14:38:41 -0800 Subject: [PATCH] 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 --- init/devices.cpp | 7 ++++--- init/devices.h | 6 +++--- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/init/devices.cpp b/init/devices.cpp index 4de1e2030..2cdececf6 100644 --- a/init/devices.cpp +++ b/init/devices.cpp @@ -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 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 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 subsystem_paths = { sysfs_mount_point_ + "/bus/scsi", }; diff --git a/init/devices.h b/init/devices.h index 8b6cf6cb1..67a3d00b1 100644 --- a/init/devices.h +++ b/init/devices.h @@ -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& 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 GetDevicePermissions( const std::string& path, const std::vector& links) const; void MakeDevice(const std::string& path, bool block, int major, int minor,