Use const refs to strings in PropertyProvider
These don't actually need to be copies.
Bug: 251196347
Test: connect a touchpad to a device, check dumpsys input
Test: atest inputflinger_tests:PropertyProviderTest
Change-Id: I91c518d422fcc55f933d6df132d8e748e02d7554
diff --git a/services/inputflinger/reader/mapper/gestures/PropertyProvider.cpp b/services/inputflinger/reader/mapper/gestures/PropertyProvider.cpp
index cd18cd3..089f45a 100644
--- a/services/inputflinger/reader/mapper/gestures/PropertyProvider.cpp
+++ b/services/inputflinger/reader/mapper/gestures/PropertyProvider.cpp
@@ -68,11 +68,11 @@
.free_fn = freeProperty,
};
-bool PropertyProvider::hasProperty(const std::string name) const {
+bool PropertyProvider::hasProperty(const std::string& name) const {
return mProperties.find(name) != mProperties.end();
}
-GesturesProp& PropertyProvider::getProperty(const std::string name) {
+GesturesProp& PropertyProvider::getProperty(const std::string& name) {
return mProperties.at(name);
}
@@ -84,7 +84,7 @@
return dump;
}
-GesturesProp* PropertyProvider::createIntArrayProperty(const std::string name, int* loc,
+GesturesProp* PropertyProvider::createIntArrayProperty(const std::string& name, int* loc,
size_t count, const int* init) {
const auto [it, inserted] =
mProperties.insert(std::pair{name, GesturesProp(name, loc, count, init)});
@@ -92,7 +92,7 @@
return &it->second;
}
-GesturesProp* PropertyProvider::createBoolArrayProperty(const std::string name,
+GesturesProp* PropertyProvider::createBoolArrayProperty(const std::string& name,
GesturesPropBool* loc, size_t count,
const GesturesPropBool* init) {
const auto [it, inserted] =
@@ -101,7 +101,7 @@
return &it->second;
}
-GesturesProp* PropertyProvider::createRealArrayProperty(const std::string name, double* loc,
+GesturesProp* PropertyProvider::createRealArrayProperty(const std::string& name, double* loc,
size_t count, const double* init) {
const auto [it, inserted] =
mProperties.insert(std::pair{name, GesturesProp(name, loc, count, init)});
@@ -109,7 +109,7 @@
return &it->second;
}
-GesturesProp* PropertyProvider::createStringProperty(const std::string name, const char** loc,
+GesturesProp* PropertyProvider::createStringProperty(const std::string& name, const char** loc,
const char* const init) {
const auto [it, inserted] = mProperties.insert(std::pair{name, GesturesProp(name, loc, init)});
LOG_ALWAYS_FATAL_IF(!inserted, "Gesture property \"%s\" already exists.", name.c_str());
diff --git a/services/inputflinger/reader/mapper/gestures/PropertyProvider.h b/services/inputflinger/reader/mapper/gestures/PropertyProvider.h
index c21260f..50451a3 100644
--- a/services/inputflinger/reader/mapper/gestures/PropertyProvider.h
+++ b/services/inputflinger/reader/mapper/gestures/PropertyProvider.h
@@ -31,18 +31,18 @@
// Implementation of a gestures library property provider, which provides configuration parameters.
class PropertyProvider {
public:
- bool hasProperty(const std::string name) const;
- GesturesProp& getProperty(const std::string name);
+ bool hasProperty(const std::string& name) const;
+ GesturesProp& getProperty(const std::string& name);
std::string dump() const;
// Methods to be called by the gestures library:
- GesturesProp* createIntArrayProperty(const std::string name, int* loc, size_t count,
+ GesturesProp* createIntArrayProperty(const std::string& name, int* loc, size_t count,
const int* init);
- GesturesProp* createBoolArrayProperty(const std::string name, GesturesPropBool* loc,
+ GesturesProp* createBoolArrayProperty(const std::string& name, GesturesPropBool* loc,
size_t count, const GesturesPropBool* init);
- GesturesProp* createRealArrayProperty(const std::string name, double* loc, size_t count,
+ GesturesProp* createRealArrayProperty(const std::string& name, double* loc, size_t count,
const double* init);
- GesturesProp* createStringProperty(const std::string name, const char** loc,
+ GesturesProp* createStringProperty(const std::string& name, const char** loc,
const char* const init);
void freeProperty(GesturesProp* prop);