michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: #include "nsHtml5DependentUTF16Buffer.h" michael@0: michael@0: nsHtml5DependentUTF16Buffer::nsHtml5DependentUTF16Buffer(const nsAString& aToWrap) michael@0: : nsHtml5UTF16Buffer(const_cast (aToWrap.BeginReading()), michael@0: aToWrap.Length()) michael@0: { michael@0: MOZ_COUNT_CTOR(nsHtml5DependentUTF16Buffer); michael@0: } michael@0: michael@0: nsHtml5DependentUTF16Buffer::~nsHtml5DependentUTF16Buffer() michael@0: { michael@0: MOZ_COUNT_DTOR(nsHtml5DependentUTF16Buffer); michael@0: } michael@0: michael@0: already_AddRefed michael@0: nsHtml5DependentUTF16Buffer::FalliblyCopyAsOwningBuffer() michael@0: { michael@0: int32_t newLength = getEnd() - getStart(); michael@0: nsRefPtr newObj = michael@0: nsHtml5OwningUTF16Buffer::FalliblyCreate(newLength); michael@0: if (!newObj) { michael@0: return nullptr; michael@0: } michael@0: newObj->setEnd(newLength); michael@0: memcpy(newObj->getBuffer(), michael@0: getBuffer() + getStart(), michael@0: newLength * sizeof(char16_t)); michael@0: return newObj.forget(); michael@0: }