☠☠ backed out by 8d1f842be870 ☠ ☠ | |
author | David Major <dmajor@mozilla.com> |
Tue, 14 Mar 2017 15:26:36 +1300 | |
changeset 347438 | d9b330f9bc245c8bea3333aef3d47e1454d47180 |
parent 347437 | 2b460fe020afba0b8e3bee63dbab781e63350ef2 |
child 347439 | a96390e044e0e82051335ad050222d1db73da65a |
push id | 31496 |
push user | cbook@mozilla.com |
push date | Tue, 14 Mar 2017 13:21:57 +0000 |
treeherder | mozilla-central@9a26ed658fdc [default view] [failures only] |
perfherder | [talos] [build metrics] [platform microbench] (compared to previous push) |
reviewers | dbaron |
bugs | 1344629 |
milestone | 55.0a1 |
first release with | nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
|
last release without | nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
|
--- a/editor/libeditor/HTMLEditRules.cpp +++ b/editor/libeditor/HTMLEditRules.cpp @@ -3459,17 +3459,18 @@ nsresult HTMLEditRules::WillMakeDefListItem(Selection* aSelection, const nsAString *aItemType, bool aEntireList, bool* aCancel, bool* aHandled) { // for now we let WillMakeList handle this NS_NAMED_LITERAL_STRING(listType, "dl"); - return WillMakeList(aSelection, &listType, aEntireList, nullptr, aCancel, aHandled, aItemType); + return WillMakeList(aSelection, &listType.AsString(), aEntireList, nullptr, + aCancel, aHandled, aItemType); } nsresult HTMLEditRules::WillMakeBasicBlock(Selection& aSelection, const nsAString& aBlockType, bool* aCancel, bool* aHandled) {
--- a/editor/libeditor/HTMLStyleEditor.cpp +++ b/editor/libeditor/HTMLStyleEditor.cpp @@ -1628,18 +1628,18 @@ HTMLEditor::GetFontFaceState(bool* aMixe NS_ENSURE_TRUE(aMixed, NS_ERROR_FAILURE); *aMixed = true; outFace.Truncate(); bool first, any, all; NS_NAMED_LITERAL_STRING(attr, "face"); nsresult rv = - GetInlinePropertyBase(*nsGkAtoms::font, &attr, nullptr, &first, &any, - &all, &outFace); + GetInlinePropertyBase(*nsGkAtoms::font, &attr.AsString(), nullptr, &first, + &any, &all, &outFace); NS_ENSURE_SUCCESS(rv, rv); if (any && !all) { return NS_OK; // mixed } if (all) { *aMixed = false; return NS_OK; } @@ -1671,18 +1671,18 @@ HTMLEditor::GetFontColorState(bool* aMix NS_ENSURE_TRUE(aMixed, NS_ERROR_NULL_POINTER); *aMixed = true; aOutColor.Truncate(); NS_NAMED_LITERAL_STRING(colorStr, "color"); bool first, any, all; nsresult rv = - GetInlinePropertyBase(*nsGkAtoms::font, &colorStr, nullptr, &first, - &any, &all, &aOutColor); + GetInlinePropertyBase(*nsGkAtoms::font, &colorStr.AsString(), nullptr, + &first, &any, &all, &aOutColor); NS_ENSURE_SUCCESS(rv, rv); if (any && !all) { return NS_OK; // mixed } if (all) { *aMixed = false; return NS_OK; }
--- a/editor/libeditor/TextEditRules.cpp +++ b/editor/libeditor/TextEditRules.cpp @@ -380,18 +380,19 @@ TextEditRules::WillInsertBreak(Selection if (IsSingleLineEditor()) { *aCancel = true; } else { // handle docs with a max length // NOTE, this function copies inString into outString for us. NS_NAMED_LITERAL_STRING(inString, "\n"); nsAutoString outString; bool didTruncate; - nsresult rv = TruncateInsertionIfNeeded(aSelection, &inString, &outString, - aMaxLength, &didTruncate); + nsresult rv = TruncateInsertionIfNeeded(aSelection, &inString.AsString(), + &outString, aMaxLength, + &didTruncate); NS_ENSURE_SUCCESS(rv, rv); if (didTruncate) { *aCancel = true; return NS_OK; } *aCancel = false;
--- a/xpcom/string/nsTLiteralString.h +++ b/xpcom/string/nsTLiteralString.h @@ -1,44 +1,59 @@ /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ /* vim: set ts=8 sts=2 et sw=2 tw=80: */ /* This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ - /** * nsTLiteralString_CharT * * Stores a null-terminated, immutable sequence of characters. * - * Subclass of nsTString that restricts string value to a literal - * character sequence. This class does not own its data. The data is - * assumed to be permanent. In practice this is true because this code - * is only usable by and for libxul. + * nsTString-lookalike that restricts its string value to a literal character + * sequence. Can be implicitly cast to const nsTString& (the const is + * essential, since this class's data are not writable). The data are assumed + * to be static (permanent) and therefore, as an optimization, this class + * does not have a destructor. */ -class nsTLiteralString_CharT : public nsTString_CharT +class nsTLiteralString_CharT : public mozilla::detail::nsTStringRepr_CharT { public: typedef nsTLiteralString_CharT self_type; public: /** * constructor */ template<size_type N> explicit nsTLiteralString_CharT(const char_type (&aStr)[N]) - : string_type(const_cast<char_type*>(aStr), N - 1, F_TERMINATED | F_LITERAL) + : base_string_type(const_cast<char_type*>(aStr), N - 1, F_TERMINATED | F_LITERAL) { } /** + * For compatibility with existing code that requires const ns[C]String*. + * Use sparingly. If possible, rewrite code to use const ns[C]String& + * and the implicit cast will just work. + */ + const nsTString_CharT& AsString() const + { + return *reinterpret_cast<const nsTString_CharT*>(this); + } + + operator const nsTString_CharT&() const + { + return AsString(); + } + + /** * Prohibit get() on temporaries as in nsLiteralCString("x").get(). * These should be written as just "x", using a string literal directly. */ #if defined(CharT_is_PRUnichar) && defined(MOZ_USE_CHAR16_WRAPPER) char16ptr_t get() const && = delete; char16ptr_t get() const & #else const char_type* get() const && = delete; @@ -48,9 +63,15 @@ public: return mData; } private: // NOT TO BE IMPLEMENTED template<size_type N> nsTLiteralString_CharT(char_type (&aStr)[N]) = delete; + + self_type& operator=(const self_type&) = delete; }; + +static_assert(sizeof(nsTLiteralString_CharT) == sizeof(nsTString_CharT), + "nsTLiteralString_CharT can masquerade as nsTString_CharT, " + "so they must have identical layout");