xpcom/string/src/nsTString.cpp

Thu, 22 Jan 2015 13:21:57 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Thu, 22 Jan 2015 13:21:57 +0100
branch
TOR_BUG_9701
changeset 15
b8a032363ba2
permissions
-rw-r--r--

Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6

     1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
     2 /* vim:set ts=2 sw=2 sts=2 et cindent: */
     3 /* This Source Code Form is subject to the terms of the Mozilla Public
     4  * License, v. 2.0. If a copy of the MPL was not distributed with this
     5  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
     7 nsTAdoptingString_CharT&
     8 nsTAdoptingString_CharT::operator=( const self_type& str )
     9   {
    10     // This'll violate the constness of this argument, that's just
    11     // the nature of this class...
    12     self_type* mutable_str = const_cast<self_type*>(&str);
    14     if (str.mFlags & F_OWNED)
    15       {
    16         // We want to do what Adopt() does, but without actually incrementing
    17         // the Adopt count.  Note that we can be a little more straightforward
    18         // about this than Adopt() is, because we know that str.mData is
    19         // non-null.  Should we be able to assert that str is not void here?
    20         NS_ASSERTION(str.mData, "String with null mData?");
    21         Finalize();
    22         mData = str.mData;
    23         mLength = str.mLength;
    24         SetDataFlags(F_TERMINATED | F_OWNED);
    26         // Make str forget the buffer we just took ownership of.
    27         new (mutable_str) self_type();
    28       }
    29     else
    30       {
    31         Assign(str);
    33         mutable_str->Truncate();
    34       }
    36     return *this;
    37   }
    39 void
    40 nsTString_CharT::Rebind( const char_type* data, size_type length )
    41   {
    42     // If we currently own a buffer, release it.
    43     Finalize();
    45     mData = const_cast<char_type*>(data);
    46     mLength = length;
    47     SetDataFlags(F_TERMINATED);
    48     AssertValidDepedentString();
    49   }

mercurial