Use string_view for pref interface to reduce copy
If you pass in a static string literal like "Hello World!", then with
parameter type of const string& you need to construct a new string
object, requiring a copy. It will also require a copy if your data is in
another container, for example std::vector<char> . In update_engine, we
store manifest bytes in std::vector, and sometimes we want to save that
manifest to disk. This CL can help us reduce copy of the manifest(up to
2MB).
Test: treehugger
Change-Id: I70feb4c0673c174fd47f02c4bd41994f74cda743
diff --git a/common/prefs_interface.h b/common/prefs_interface.h
index 866d0ca..e773a35 100644
--- a/common/prefs_interface.h
+++ b/common/prefs_interface.h
@@ -52,7 +52,7 @@
// Associates |key| with a string |value|. Returns true on success,
// false otherwise.
- virtual bool SetString(const std::string& key, const std::string& value) = 0;
+ virtual bool SetString(const std::string& key, std::string_view value) = 0;
// Gets an int64_t |value| associated with |key|. Returns true on
// success, false on failure (including when the |key| is not