CachedProperty: take string by value in ctor.
Test: mma
Change-Id: Ifcb32c204c4fbfe64fe91ff3b67822b1340fc42f
diff --git a/include/android-base/properties.h b/include/android-base/properties.h
index 021f466..a1ad729 100644
--- a/include/android-base/properties.h
+++ b/include/android-base/properties.h
@@ -75,6 +75,9 @@
// this class helps optimize those lookups.
class CachedProperty {
public:
+ explicit CachedProperty(std::string property_name);
+
+ // Kept for ABI compatibility.
explicit CachedProperty(const char* property_name);
// Returns the current value of the underlying system property as cheaply as possible.
diff --git a/properties.cpp b/properties.cpp
index d925b10..7e30c82 100644
--- a/properties.cpp
+++ b/properties.cpp
@@ -221,8 +221,8 @@
return (WaitForPropertyCreation(key, relative_timeout, start_time) != nullptr);
}
-CachedProperty::CachedProperty(const char* property_name)
- : property_name_(property_name),
+CachedProperty::CachedProperty(std::string property_name)
+ : property_name_(std::move(property_name)),
prop_info_(nullptr),
cached_area_serial_(0),
cached_property_serial_(0),
@@ -231,6 +231,9 @@
static_assert(sizeof(cached_value_) == PROP_VALUE_MAX);
}
+CachedProperty::CachedProperty(const char* property_name)
+ : CachedProperty(std::string(property_name)) {}
+
const char* CachedProperty::Get(bool* changed) {
std::optional<uint32_t> initial_property_serial = cached_property_serial_;