Bug 1609862 - Display more detailed memory info in resource usage report. r=froydnj
[gecko.git] / xpcom / string / nsTDependentString.cpp
blobf8a374367f7ab26981d304846d1aef7c343b21a9
1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* vim: set ts=8 sts=2 et sw=2 tw=80: */
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 template <typename T>
8 nsTDependentString<T>::nsTDependentString(const char_type* aStart,
9 const char_type* aEnd)
10 : string_type(const_cast<char_type*>(aStart), uint32_t(aEnd - aStart),
11 DataFlags::TERMINATED, ClassFlags(0)) {
12 MOZ_RELEASE_ASSERT(aStart <= aEnd, "Overflow!");
13 this->AssertValidDependentString();
16 template <typename T>
17 void nsTDependentString<T>::Rebind(const string_type& str, uint32_t startPos) {
18 MOZ_ASSERT(str.GetDataFlags() & DataFlags::TERMINATED,
19 "Unterminated flat string");
21 // If we currently own a buffer, release it.
22 this->Finalize();
24 size_type strLength = str.Length();
26 if (startPos > strLength) {
27 startPos = strLength;
30 char_type* newData =
31 const_cast<char_type*>(static_cast<const char_type*>(str.Data())) +
32 startPos;
33 size_type newLen = strLength - startPos;
34 DataFlags newDataFlags =
35 str.GetDataFlags() & (DataFlags::TERMINATED | DataFlags::LITERAL);
36 this->SetData(newData, newLen, newDataFlags);
39 template <typename T>
40 void nsTDependentString<T>::Rebind(const char_type* aStart,
41 const char_type* aEnd) {
42 MOZ_RELEASE_ASSERT(aStart <= aEnd, "Overflow!");
43 this->Rebind(aStart, uint32_t(aEnd - aStart));