зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1076587 - Allow nsAttrValueOrString helper to accept potentially-null pointers r=bz
This commit is contained in:
Родитель
84b7950df8
Коммит
ce94155998
|
@ -12,6 +12,11 @@ nsAttrValueOrString::String() const
|
|||
return *mStringPtr;
|
||||
}
|
||||
|
||||
if (!mAttrValue) {
|
||||
mStringPtr = &mCheapString;
|
||||
return *mStringPtr;
|
||||
}
|
||||
|
||||
if (mAttrValue->Type() == nsAttrValue::eString) {
|
||||
mCheapString = mAttrValue->GetStringValue();
|
||||
mStringPtr = &mCheapString;
|
||||
|
|
|
@ -8,6 +8,9 @@
|
|||
* because constructing an nsAttrValue from an nsAString can be expensive when
|
||||
* the buffer of the string is not shared.
|
||||
*
|
||||
* This treats nsAttrValueOrString(nullptr) as the empty string,
|
||||
* to help with contexts where a null pointer denotes an empty value.
|
||||
*
|
||||
* Since a raw pointer to the passed-in string is kept, this class should only
|
||||
* be used on the stack.
|
||||
*/
|
||||
|
@ -26,12 +29,25 @@ public:
|
|||
, mStringPtr(&aValue)
|
||||
, mCheapString(nullptr)
|
||||
{ }
|
||||
|
||||
explicit nsAttrValueOrString(const nsAString* aValue)
|
||||
: mAttrValue(nullptr)
|
||||
, mStringPtr(aValue)
|
||||
, mCheapString(nullptr)
|
||||
{ }
|
||||
|
||||
explicit nsAttrValueOrString(const nsAttrValue& aValue)
|
||||
: mAttrValue(&aValue)
|
||||
, mStringPtr(nullptr)
|
||||
, mCheapString(nullptr)
|
||||
{ }
|
||||
|
||||
explicit nsAttrValueOrString(const nsAttrValue* aValue)
|
||||
: mAttrValue(aValue)
|
||||
, mStringPtr(nullptr)
|
||||
, mCheapString(nullptr)
|
||||
{ }
|
||||
|
||||
/**
|
||||
* Returns a reference to the string value of the contents of this object.
|
||||
*
|
||||
|
|
Загрузка…
Ссылка в новой задаче