init: Use ConsumePrefix() instead of open coding in GetBlockDeviceSymlinks()
In GetBlockDeviceSymlinks() we may need to strip the
"/devices/platform/" or "/devices/" from a string. Use the helper
ConsumePrefix() to do this, which is more convenient and readable.
This change is intended to be a no-op and just a cleanup.
Bug: 316324155
Test: Build and boot
Change-Id: I1adb1906ec37ff8f6f505abc5f26e1e3b157e608
diff --git a/init/devices.cpp b/init/devices.cpp
index 0af843f..3054d3a 100644
--- a/init/devices.cpp
+++ b/init/devices.cpp
@@ -45,6 +45,7 @@
using namespace std::chrono_literals;
using android::base::Basename;
+using android::base::ConsumePrefix;
using android::base::Dirname;
using android::base::ReadFileToString;
using android::base::Readlink;
@@ -386,11 +387,10 @@
// Skip /devices/platform or /devices/ if present
static constexpr std::string_view devices_platform_prefix = "/devices/platform/";
static constexpr std::string_view devices_prefix = "/devices/";
+ std::string_view str = device;
- if (StartsWith(device, devices_platform_prefix)) {
- device = device.substr(devices_platform_prefix.length());
- } else if (StartsWith(device, devices_prefix)) {
- device = device.substr(devices_prefix.length());
+ if (ConsumePrefix(&str, devices_platform_prefix) || ConsumePrefix(&str, devices_prefix)) {
+ device = str;
}
type = "platform";