зеркало из https://github.com/mozilla/gecko-dev.git
Bug 859817 - Make nsStringBuffer::Alloc return already_AddRefed; r=bz
This commit is contained in:
Родитель
05cfec22ce
Коммит
b8a4c64af3
|
@ -373,7 +373,7 @@ void
|
|||
nsAttrValue::SetTo(const nsAString& aValue)
|
||||
{
|
||||
ResetIfSet();
|
||||
nsStringBuffer* buf = GetStringBuffer(aValue);
|
||||
nsStringBuffer* buf = GetStringBuffer(aValue).get();
|
||||
if (buf) {
|
||||
SetPtrValueAndType(buf, eStringBase);
|
||||
}
|
||||
|
@ -1526,7 +1526,7 @@ nsAttrValue::ParsePositiveIntValue(const nsAString& aString)
|
|||
void
|
||||
nsAttrValue::SetColorValue(nscolor aColor, const nsAString& aString)
|
||||
{
|
||||
nsStringBuffer* buf = GetStringBuffer(aString);
|
||||
nsStringBuffer* buf = GetStringBuffer(aString).get();
|
||||
if (!buf) {
|
||||
return;
|
||||
}
|
||||
|
@ -1717,7 +1717,7 @@ nsAttrValue::SetMiscAtomOrString(const nsAString* aValue)
|
|||
reinterpret_cast<uintptr_t>(atom.forget().get()) | eAtomBase;
|
||||
}
|
||||
} else {
|
||||
nsStringBuffer* buf = GetStringBuffer(*aValue);
|
||||
nsStringBuffer* buf = GetStringBuffer(*aValue).get();
|
||||
if (buf) {
|
||||
cont->mStringBits = reinterpret_cast<uintptr_t>(buf) | eStringBase;
|
||||
}
|
||||
|
@ -1853,7 +1853,7 @@ nsAttrValue::EnsureEmptyAtomArray()
|
|||
return true;
|
||||
}
|
||||
|
||||
nsStringBuffer*
|
||||
already_AddRefed<nsStringBuffer>
|
||||
nsAttrValue::GetStringBuffer(const nsAString& aValue) const
|
||||
{
|
||||
uint32_t len = aValue.Length();
|
||||
|
@ -1861,10 +1861,9 @@ nsAttrValue::GetStringBuffer(const nsAString& aValue) const
|
|||
return nullptr;
|
||||
}
|
||||
|
||||
nsStringBuffer* buf = nsStringBuffer::FromString(aValue);
|
||||
nsRefPtr<nsStringBuffer> buf = nsStringBuffer::FromString(aValue);
|
||||
if (buf && (buf->StorageSize()/sizeof(PRUnichar) - 1) == len) {
|
||||
buf->AddRef();
|
||||
return buf;
|
||||
return buf.forget();
|
||||
}
|
||||
|
||||
buf = nsStringBuffer::Alloc((len + 1) * sizeof(PRUnichar));
|
||||
|
@ -1874,7 +1873,7 @@ nsAttrValue::GetStringBuffer(const nsAString& aValue) const
|
|||
PRUnichar *data = static_cast<PRUnichar*>(buf->Data());
|
||||
CopyUnicodeTo(aValue, 0, data, len);
|
||||
data[len] = PRUnichar(0);
|
||||
return buf;
|
||||
return buf.forget();
|
||||
}
|
||||
|
||||
int32_t
|
||||
|
|
|
@ -415,7 +415,8 @@ private:
|
|||
// exist already.
|
||||
MiscContainer* EnsureEmptyMiscContainer();
|
||||
bool EnsureEmptyAtomArray();
|
||||
nsStringBuffer* GetStringBuffer(const nsAString& aValue) const;
|
||||
already_AddRefed<nsStringBuffer>
|
||||
GetStringBuffer(const nsAString& aValue) const;
|
||||
// aStrict is set true if stringifying the return value equals with
|
||||
// aValue.
|
||||
int32_t StringToInteger(const nsAString& aValue,
|
||||
|
|
|
@ -1008,7 +1008,7 @@ nsDocumentEncoder::EncodeToString(nsAString& aOutputString)
|
|||
nsString output;
|
||||
static const size_t bufferSize = 2048;
|
||||
if (!mCachedBuffer) {
|
||||
mCachedBuffer = nsStringBuffer::Alloc(bufferSize);
|
||||
mCachedBuffer = nsStringBuffer::Alloc(bufferSize).get();
|
||||
}
|
||||
NS_ASSERTION(!mCachedBuffer->IsReadonly(),
|
||||
"DocumentEncoder shouldn't keep reference to non-readonly buffer!");
|
||||
|
|
|
@ -624,10 +624,9 @@ nsCSSValue::EqualsFunction(nsCSSKeyword aFunctionId) const
|
|||
already_AddRefed<nsStringBuffer>
|
||||
nsCSSValue::BufferFromString(const nsString& aValue)
|
||||
{
|
||||
nsStringBuffer* buffer = nsStringBuffer::FromString(aValue);
|
||||
nsRefPtr<nsStringBuffer> buffer = nsStringBuffer::FromString(aValue);
|
||||
if (buffer) {
|
||||
buffer->AddRef();
|
||||
return buffer;
|
||||
return buffer.forget();
|
||||
}
|
||||
|
||||
nsString::size_type length = aValue.Length();
|
||||
|
@ -643,7 +642,7 @@ nsCSSValue::BufferFromString(const nsString& aValue)
|
|||
nsCharTraits<PRUnichar>::copy(data, aValue.get(), length);
|
||||
// Null-terminate.
|
||||
data[length] = 0;
|
||||
return buffer;
|
||||
return buffer.forget();
|
||||
}
|
||||
|
||||
namespace {
|
||||
|
|
|
@ -8,12 +8,10 @@
|
|||
nsHtml5Atom::nsHtml5Atom(const nsAString& aString)
|
||||
{
|
||||
mLength = aString.Length();
|
||||
nsStringBuffer* buf = nsStringBuffer::FromString(aString);
|
||||
nsRefPtr<nsStringBuffer> buf = nsStringBuffer::FromString(aString);
|
||||
if (buf) {
|
||||
buf->AddRef();
|
||||
mString = static_cast<PRUnichar*>(buf->Data());
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
buf = nsStringBuffer::Alloc((mLength + 1) * sizeof(PRUnichar));
|
||||
mString = static_cast<PRUnichar*>(buf->Data());
|
||||
CopyUnicodeTo(aString, 0, mString, mLength);
|
||||
|
@ -24,6 +22,9 @@ nsHtml5Atom::nsHtml5Atom(const nsAString& aString)
|
|||
NS_ASSERTION(buf && buf->StorageSize() >= (mLength+1) * sizeof(PRUnichar),
|
||||
"enough storage");
|
||||
NS_ASSERTION(Equals(aString), "correct data");
|
||||
|
||||
// Take ownership of buffer
|
||||
buf.forget();
|
||||
}
|
||||
|
||||
nsHtml5Atom::~nsHtml5Atom()
|
||||
|
|
|
@ -299,12 +299,10 @@ NS_PurgeAtomTable()
|
|||
AtomImpl::AtomImpl(const nsAString& aString, PLDHashNumber aKeyHash)
|
||||
{
|
||||
mLength = aString.Length();
|
||||
nsStringBuffer* buf = nsStringBuffer::FromString(aString);
|
||||
nsRefPtr<nsStringBuffer> buf = nsStringBuffer::FromString(aString);
|
||||
if (buf) {
|
||||
buf->AddRef();
|
||||
mString = static_cast<PRUnichar*>(buf->Data());
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
buf = nsStringBuffer::Alloc((mLength + 1) * sizeof(PRUnichar));
|
||||
mString = static_cast<PRUnichar*>(buf->Data());
|
||||
CopyUnicodeTo(aString, 0, mString, mLength);
|
||||
|
@ -319,6 +317,9 @@ AtomImpl::AtomImpl(const nsAString& aString, PLDHashNumber aKeyHash)
|
|||
NS_ASSERTION(buf && buf->StorageSize() >= (mLength+1) * sizeof(PRUnichar),
|
||||
"enough storage");
|
||||
NS_ASSERTION(Equals(aString), "correct data");
|
||||
|
||||
// Take ownership of buffer
|
||||
buf.forget();
|
||||
}
|
||||
|
||||
AtomImpl::AtomImpl(nsStringBuffer* aStringBuffer, uint32_t aLength,
|
||||
|
|
|
@ -7,6 +7,7 @@
|
|||
#ifndef nsStringBuffer_h__
|
||||
#define nsStringBuffer_h__
|
||||
|
||||
template<class T> struct already_AddRefed;
|
||||
|
||||
/**
|
||||
* This structure precedes the string buffers "we" allocate. It may be the
|
||||
|
@ -41,7 +42,7 @@ class nsStringBuffer
|
|||
*
|
||||
* @return new string buffer or null if out of memory.
|
||||
*/
|
||||
static nsStringBuffer* Alloc(size_t storageSize);
|
||||
static already_AddRefed<nsStringBuffer> Alloc(size_t storageSize);
|
||||
|
||||
/**
|
||||
* Resizes the given string buffer to the specified storage size. This
|
||||
|
|
|
@ -21,6 +21,7 @@
|
|||
#include "pratom.h"
|
||||
#include "prprf.h"
|
||||
#include "nsStaticAtom.h"
|
||||
#include "nsCOMPtr.h"
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
|
@ -165,7 +166,7 @@ nsStringBuffer::Release()
|
|||
/**
|
||||
* Alloc returns a pointer to a new string header with set capacity.
|
||||
*/
|
||||
nsStringBuffer*
|
||||
already_AddRefed<nsStringBuffer>
|
||||
nsStringBuffer::Alloc(size_t size)
|
||||
{
|
||||
NS_ASSERTION(size != 0, "zero capacity allocation not allowed");
|
||||
|
@ -183,7 +184,7 @@ nsStringBuffer::Alloc(size_t size)
|
|||
hdr->mStorageSize = size;
|
||||
NS_LOG_ADDREF(hdr, 1, "nsStringBuffer", sizeof(*hdr));
|
||||
}
|
||||
return hdr;
|
||||
return dont_AddRef(hdr);
|
||||
}
|
||||
|
||||
nsStringBuffer*
|
||||
|
|
|
@ -127,7 +127,7 @@ nsTSubstring_CharT::MutatePrep( size_type capacity, char_type** oldData, uint32_
|
|||
// make use of our F_OWNED or F_FIXED buffers because they are not
|
||||
// large enough.
|
||||
|
||||
nsStringBuffer* newHdr = nsStringBuffer::Alloc(storageSize);
|
||||
nsStringBuffer* newHdr = nsStringBuffer::Alloc(storageSize).get();
|
||||
if (!newHdr)
|
||||
return false; // we are still in a consistent state
|
||||
|
||||
|
|
Загрузка…
Ссылка в новой задаче