Skip to content

Commit 8ec7e64

Browse files
markchandlera-maurice
authored andcommitted
Firebase cpp: Changed mutable_string() const to support returning value of static or small strings to fix non obvious behavior difference between this and the non const version.
Due to the wide spread use of mutable_string() to access string value regardless of string type, this function has changed to support returning all string types as std::string to not break existing code at runtime. PiperOrigin-RevId: 275051789
1 parent 3b05efe commit 8ec7e64

File tree

1 file changed

+7
-7
lines changed

1 file changed

+7
-7
lines changed

app/src/include/firebase/variant.h

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -692,16 +692,16 @@ class Variant {
692692
return value_.small_string;
693693
}
694694

695-
/// @brief Const accessor for a Variant containing a mutable string only.
695+
/// @brief Const accessor for a Variant containing a string.
696696
///
697697
/// @note Unlike the non-const accessor, this accessor cannot "promote" a
698-
/// static string to mutable, and thus will assert if the Variant you pass in
699-
/// is not of MutableString type.
698+
/// static string to mutable, and thus returns a std::string copy instead of a
699+
/// const reference to a std::string
700700
///
701-
/// @return Reference to the string contained in this Variant.
702-
const std::string& mutable_string() const {
703-
assert_is_type(kTypeMutableString);
704-
return *value_.mutable_string_value;
701+
/// @return std::string with the string contents contained in this Variant.
702+
std::string mutable_string() const {
703+
assert_is_string();
704+
return string_value();
705705
}
706706

707707
/// @brief Const accessor for a Variant containing a vector of Variant data.

0 commit comments

Comments
 (0)