Commit 7f541107 authored by andersca@apple.com's avatar andersca@apple.com

Vector::releaseBuffer should return an OwnPtr

https://bugs.webkit.org/show_bug.cgi?id=120718

Reviewed by Andreas Kling.

Source/WebCore:

Change FormStreamFields::currentData to an OwnPtr.

* platform/network/cf/FormDataStreamCFNet.cpp:
(WebCore::closeCurrentStream):
(WebCore::advanceCurrentStream):
(WebCore::formCreate):

Source/WTF:

Change Vector::releaseBuffer() to return an OwnPtr. I intentionally chose
to use an OwnPtr over a PassOwnPtr since we're trying to move away from PassOwnPtr objects.

Fix fallout from this change by adopting OwnPtr/PassOwnPtr in StringBuffer and the two StringImpl
constructors that adopt the passed in pointer.

* wtf/Vector.h:
* wtf/text/StringBuffer.h:
* wtf/text/StringImpl.h:

git-svn-id: http://svn.webkit.org/repository/webkit/trunk@155121 268f45cc-cd09-0410-ab3c-d52691b4dbfc
parent 80b077bf
2013-09-04 Anders Carlsson <andersca@apple.com>
Vector::releaseBuffer should return an OwnPtr
https://bugs.webkit.org/show_bug.cgi?id=120718
Reviewed by Andreas Kling.
Change Vector::releaseBuffer() to return an OwnPtr. I intentionally chose
to use an OwnPtr over a PassOwnPtr since we're trying to move away from PassOwnPtr objects.
Fix fallout from this change by adopting OwnPtr/PassOwnPtr in StringBuffer and the two StringImpl
constructors that adopt the passed in pointer.
* wtf/Vector.h:
* wtf/text/StringBuffer.h:
* wtf/text/StringImpl.h:
2013-09-05 Mikhail Pozdnyakov <mikhail.pozdnyakov@intel.com>
Remove String(RefPtr<StringImpl>) constructor
......
......@@ -26,6 +26,7 @@
#include <wtf/FastAllocBase.h>
#include <wtf/Noncopyable.h>
#include <wtf/NotFound.h>
#include <wtf/OwnPtr.h>
#include <wtf/StdLibExtras.h>
#include <wtf/ValueCheck.h>
#include <wtf/VectorTraits.h>
......@@ -307,12 +308,12 @@ public:
const T* buffer() const { return m_buffer; }
size_t capacity() const { return m_capacity; }
T* releaseBuffer()
OwnPtr<T> releaseBuffer()
{
T* buffer = m_buffer;
m_buffer = 0;
m_capacity = 0;
return buffer;
return adoptPtr(buffer);
}
protected:
......@@ -487,10 +488,10 @@ public:
using Base::buffer;
using Base::capacity;
T* releaseBuffer()
OwnPtr<T> releaseBuffer()
{
if (buffer() == inlineBuffer())
return 0;
return nullptr;
return Base::releaseBuffer();
}
......@@ -541,6 +542,13 @@ public:
TypeOperations::initialize(begin(), end());
}
Vector(size_t size, const T& val)
: Base(size, size)
{
if (begin())
TypeOperations::uninitializedFill(begin(), end(), val);
}
~Vector()
{
if (m_size)
......@@ -653,19 +661,12 @@ public:
shrink(size() - 1);
}
Vector(size_t size, const T& val)
: Base(size, size)
{
if (begin())
TypeOperations::uninitializedFill(begin(), end(), val);
}
void fill(const T&, size_t);
void fill(const T& val) { fill(val, size()); }
template<typename Iterator> void appendRange(Iterator start, Iterator end);
T* releaseBuffer();
OwnPtr<T> releaseBuffer();
void swap(Vector<T, inlineCapacity, OverflowHandler>& other)
{
......@@ -1152,19 +1153,19 @@ inline void Vector<T, inlineCapacity, OverflowHandler>::reverse()
}
template<typename T, size_t inlineCapacity, typename OverflowHandler>
inline T* Vector<T, inlineCapacity, OverflowHandler>::releaseBuffer()
inline OwnPtr<T> Vector<T, inlineCapacity, OverflowHandler>::releaseBuffer()
{
T* buffer = Base::releaseBuffer();
OwnPtr<T> buffer = Base::releaseBuffer();
if (inlineCapacity && !buffer && m_size) {
// If the vector had some data, but no buffer to release,
// that means it was using the inline buffer. In that case,
// we create a brand new buffer so the caller always gets one.
size_t bytes = m_size * sizeof(T);
buffer = static_cast<T*>(fastMalloc(bytes));
memcpy(buffer, data(), bytes);
buffer = adoptPtr(static_cast<T*>(fastMalloc(bytes)));
memcpy(buffer.get(), data(), bytes);
}
m_size = 0;
return buffer;
return buffer.release();
}
template<typename T, size_t inlineCapacity, typename OverflowHandler>
......
......@@ -44,12 +44,11 @@ public:
{
if (m_length > std::numeric_limits<unsigned>::max() / sizeof(CharType))
CRASH();
m_data = static_cast<CharType*>(fastMalloc(m_length * sizeof(CharType)));
m_data = adoptPtr(static_cast<CharType*>(fastMalloc(m_length * sizeof(CharType))));
}
~StringBuffer()
{
fastFree(m_data);
}
void shrink(unsigned newLength)
......@@ -63,21 +62,29 @@ public:
if (newLength > m_length) {
if (newLength > std::numeric_limits<unsigned>::max() / sizeof(UChar))
CRASH();
m_data = static_cast<UChar*>(fastRealloc(m_data, newLength * sizeof(UChar)));
m_data = adoptPtr(static_cast<UChar*>(fastRealloc(m_data.release().leakPtr(), newLength * sizeof(UChar))));
}
m_length = newLength;
}
unsigned length() const { return m_length; }
CharType* characters() { return m_data; }
CharType* characters() { return m_data.get(); }
CharType& operator[](unsigned i) { ASSERT_WITH_SECURITY_IMPLICATION(i < m_length); return m_data[i]; }
CharType& operator[](unsigned i)
{
ASSERT_WITH_SECURITY_IMPLICATION(i < m_length);
return m_data.get()[i];
}
CharType* release() { CharType* data = m_data; m_data = 0; return data; }
PassOwnPtr<CharType> release()
{
OwnPtr<CharType> data = m_data.release();
return data.release();
}
private:
unsigned m_length;
CharType* m_data;
OwnPtr<CharType> m_data;
};
} // namespace WTF
......
......@@ -28,6 +28,7 @@
#include <wtf/CompilationThread.h>
#include <wtf/Forward.h>
#include <wtf/MathExtras.h>
#include <wtf/PassOwnPtr.h>
#include <wtf/StdLibExtras.h>
#include <wtf/StringHasher.h>
#include <wtf/Vector.h>
......@@ -232,10 +233,10 @@ private:
}
// Create a StringImpl adopting ownership of the provided buffer (BufferOwned)
StringImpl(const LChar* characters, unsigned length)
StringImpl(PassOwnPtr<LChar> characters, unsigned length)
: m_refCount(s_refCountIncrement)
, m_length(length)
, m_data8(characters)
, m_data8(characters.leakPtr())
, m_buffer(0)
, m_hashAndFlags(s_hashFlag8BitBuffer | BufferOwned)
{
......@@ -273,10 +274,10 @@ private:
}
// Create a StringImpl adopting ownership of the provided buffer (BufferOwned)
StringImpl(const UChar* characters, unsigned length)
StringImpl(PassOwnPtr<UChar> characters, unsigned length)
: m_refCount(s_refCountIncrement)
, m_length(length)
, m_data16(characters)
, m_data16(characters.leakPtr())
, m_buffer(0)
, m_hashAndFlags(BufferOwned)
{
......@@ -472,7 +473,7 @@ public:
ASSERT(vector.data());
if (size > std::numeric_limits<unsigned>::max())
CRASH();
return adoptRef(new StringImpl(vector.releaseBuffer(), size));
return adoptRef(new StringImpl(vector.releaseBuffer().release(), size));
}
return empty();
}
......
2013-09-04 Anders Carlsson <andersca@apple.com>
Vector::releaseBuffer should return an OwnPtr
https://bugs.webkit.org/show_bug.cgi?id=120718
Reviewed by Andreas Kling.
Change FormStreamFields::currentData to an OwnPtr.
* platform/network/cf/FormDataStreamCFNet.cpp:
(WebCore::closeCurrentStream):
(WebCore::advanceCurrentStream):
(WebCore::formCreate):
2013-09-05 Andreas Kling <akling@apple.com>
Reverting "Cached Page and Frame don't need to be ref-counted.
......@@ -107,7 +107,7 @@ struct FormStreamFields {
#if ENABLE(BLOB)
long long currentStreamRangeLength;
#endif
char* currentData;
OwnPtr<char> currentData;
CFReadStreamRef formStream;
unsigned long long streamLength;
unsigned long long bytesSent;
......@@ -124,10 +124,8 @@ static void closeCurrentStream(FormStreamFields* form)
form->currentStreamRangeLength = BlobDataItem::toEndOfFile;
#endif
}
if (form->currentData) {
fastFree(form->currentData);
form->currentData = 0;
}
form->currentData = nullptr;
}
// Return false if we cannot advance the stream. Currently the only possible failure is that the underlying file has been removed or changed since File.slice.
......@@ -143,9 +141,9 @@ static bool advanceCurrentStream(FormStreamFields* form)
if (nextInput.m_type == FormDataElement::data) {
size_t size = nextInput.m_data.size();
char* data = nextInput.m_data.releaseBuffer();
form->currentStream = CFReadStreamCreateWithBytesNoCopy(0, reinterpret_cast<const UInt8*>(data), size, kCFAllocatorNull);
form->currentData = data;
OwnPtr<char> data = nextInput.m_data.releaseBuffer();
form->currentStream = CFReadStreamCreateWithBytesNoCopy(0, reinterpret_cast<const UInt8*>(data.get()), size, kCFAllocatorNull);
form->currentData = data.release();
} else {
#if ENABLE(BLOB)
// Check if the file has been changed or not if required.
......@@ -206,7 +204,6 @@ static void* formCreate(CFReadStreamRef stream, void* context)
#if ENABLE(BLOB)
newInfo->currentStreamRangeLength = BlobDataItem::toEndOfFile;
#endif
newInfo->currentData = 0;
newInfo->formStream = stream; // Don't retain. That would create a reference cycle.
newInfo->streamLength = formContext->streamLength;
newInfo->bytesSent = 0;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment