Thu, 15 Jan 2015 21:03:48 +0100
Integrate friendly tips from Tor colleagues to make (or not) 4.5 alpha 3;
This includes removal of overloaded (but unused) methods, and addition of
a overlooked call to DataStruct::SetData(nsISupports, uint32_t, bool.)
michael@0 | 1 | /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ |
michael@0 | 2 | /* This Source Code Form is subject to the terms of the Mozilla Public |
michael@0 | 3 | * License, v. 2.0. If a copy of the MPL was not distributed with this file, |
michael@0 | 4 | * You can obtain one at http://mozilla.org/MPL/2.0/. */ |
michael@0 | 5 | |
michael@0 | 6 | /* |
michael@0 | 7 | * A wrapper to contain either an nsAttrValue or an nsAString. This is useful |
michael@0 | 8 | * because constructing an nsAttrValue from an nsAString can be expensive when |
michael@0 | 9 | * the buffer of the string is not shared. |
michael@0 | 10 | * |
michael@0 | 11 | * Since a raw pointer to the passed-in string is kept, this class should only |
michael@0 | 12 | * be used on the stack. |
michael@0 | 13 | */ |
michael@0 | 14 | |
michael@0 | 15 | #ifndef nsAttrValueOrString_h___ |
michael@0 | 16 | #define nsAttrValueOrString_h___ |
michael@0 | 17 | |
michael@0 | 18 | #include "nsString.h" |
michael@0 | 19 | #include "nsAttrValue.h" |
michael@0 | 20 | |
michael@0 | 21 | class MOZ_STACK_CLASS nsAttrValueOrString |
michael@0 | 22 | { |
michael@0 | 23 | public: |
michael@0 | 24 | nsAttrValueOrString(const nsAString& aValue) |
michael@0 | 25 | : mAttrValue(nullptr) |
michael@0 | 26 | , mStringPtr(&aValue) |
michael@0 | 27 | , mCheapString(nullptr) |
michael@0 | 28 | { } |
michael@0 | 29 | nsAttrValueOrString(const nsAttrValue& aValue) |
michael@0 | 30 | : mAttrValue(&aValue) |
michael@0 | 31 | , mStringPtr(nullptr) |
michael@0 | 32 | , mCheapString(nullptr) |
michael@0 | 33 | { } |
michael@0 | 34 | |
michael@0 | 35 | /** |
michael@0 | 36 | * Returns a reference to the string value of the contents of this object. |
michael@0 | 37 | * |
michael@0 | 38 | * When this object points to a string or an nsAttrValue of string or atom |
michael@0 | 39 | * type this should be fairly cheap. Other nsAttrValue types will be |
michael@0 | 40 | * serialized the first time this is called and cached from thereon. |
michael@0 | 41 | */ |
michael@0 | 42 | const nsAString& String() const; |
michael@0 | 43 | |
michael@0 | 44 | /** |
michael@0 | 45 | * Compares the string representation of this object with the string |
michael@0 | 46 | * representation of an nsAttrValue. |
michael@0 | 47 | */ |
michael@0 | 48 | bool EqualsAsStrings(const nsAttrValue& aOther) const |
michael@0 | 49 | { |
michael@0 | 50 | if (mStringPtr) { |
michael@0 | 51 | return aOther.Equals(*mStringPtr, eCaseMatters); |
michael@0 | 52 | } |
michael@0 | 53 | return aOther.EqualsAsStrings(*mAttrValue); |
michael@0 | 54 | } |
michael@0 | 55 | |
michael@0 | 56 | protected: |
michael@0 | 57 | const nsAttrValue* mAttrValue; |
michael@0 | 58 | mutable const nsAString* mStringPtr; |
michael@0 | 59 | mutable nsCheapString mCheapString; |
michael@0 | 60 | }; |
michael@0 | 61 | |
michael@0 | 62 | #endif // nsAttrValueOrString_h___ |