Changeset 155121 in webkit
- Timestamp:
- Sep 5, 2013 8:20:51 AM (11 years ago)
- Location:
- trunk/Source
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/WTF/ChangeLog
r155115 r155121 1 2013-09-04 Anders Carlsson <andersca@apple.com> 2 3 Vector::releaseBuffer should return an OwnPtr 4 https://bugs.webkit.org/show_bug.cgi?id=120718 5 6 Reviewed by Andreas Kling. 7 8 Change Vector::releaseBuffer() to return an OwnPtr. I intentionally chose 9 to use an OwnPtr over a PassOwnPtr since we're trying to move away from PassOwnPtr objects. 10 11 Fix fallout from this change by adopting OwnPtr/PassOwnPtr in StringBuffer and the two StringImpl 12 constructors that adopt the passed in pointer. 13 14 * wtf/Vector.h: 15 * wtf/text/StringBuffer.h: 16 * wtf/text/StringImpl.h: 17 1 18 2013-09-05 Mikhail Pozdnyakov <mikhail.pozdnyakov@intel.com> 2 19 -
trunk/Source/WTF/wtf/Vector.h
r155106 r155121 27 27 #include <wtf/Noncopyable.h> 28 28 #include <wtf/NotFound.h> 29 #include <wtf/OwnPtr.h> 29 30 #include <wtf/StdLibExtras.h> 30 31 #include <wtf/ValueCheck.h> … … 308 309 size_t capacity() const { return m_capacity; } 309 310 310 T*releaseBuffer()311 OwnPtr<T> releaseBuffer() 311 312 { 312 313 T* buffer = m_buffer; 313 314 m_buffer = 0; 314 315 m_capacity = 0; 315 return buffer;316 return adoptPtr(buffer); 316 317 } 317 318 … … 488 489 using Base::capacity; 489 490 490 T*releaseBuffer()491 OwnPtr<T> releaseBuffer() 491 492 { 492 493 if (buffer() == inlineBuffer()) 493 return 0;494 return nullptr; 494 495 return Base::releaseBuffer(); 495 496 } … … 540 541 if (begin()) 541 542 TypeOperations::initialize(begin(), end()); 543 } 544 545 Vector(size_t size, const T& val) 546 : Base(size, size) 547 { 548 if (begin()) 549 TypeOperations::uninitializedFill(begin(), end(), val); 542 550 } 543 551 … … 654 662 } 655 663 656 Vector(size_t size, const T& val)657 : Base(size, size)658 {659 if (begin())660 TypeOperations::uninitializedFill(begin(), end(), val);661 }662 663 664 void fill(const T&, size_t); 664 665 void fill(const T& val) { fill(val, size()); } … … 666 667 template<typename Iterator> void appendRange(Iterator start, Iterator end); 667 668 668 T*releaseBuffer();669 OwnPtr<T> releaseBuffer(); 669 670 670 671 void swap(Vector<T, inlineCapacity, OverflowHandler>& other) … … 1153 1154 1154 1155 template<typename T, size_t inlineCapacity, typename OverflowHandler> 1155 inline T*Vector<T, inlineCapacity, OverflowHandler>::releaseBuffer()1156 { 1157 T*buffer = Base::releaseBuffer();1156 inline OwnPtr<T> Vector<T, inlineCapacity, OverflowHandler>::releaseBuffer() 1157 { 1158 OwnPtr<T> buffer = Base::releaseBuffer(); 1158 1159 if (inlineCapacity && !buffer && m_size) { 1159 1160 // If the vector had some data, but no buffer to release, … … 1161 1162 // we create a brand new buffer so the caller always gets one. 1162 1163 size_t bytes = m_size * sizeof(T); 1163 buffer = static_cast<T*>(fastMalloc(bytes));1164 memcpy(buffer , data(), bytes);1164 buffer = adoptPtr(static_cast<T*>(fastMalloc(bytes))); 1165 memcpy(buffer.get(), data(), bytes); 1165 1166 } 1166 1167 m_size = 0; 1167 return buffer ;1168 return buffer.release(); 1168 1169 } 1169 1170 -
trunk/Source/WTF/wtf/text/StringBuffer.h
r141816 r155121 45 45 if (m_length > std::numeric_limits<unsigned>::max() / sizeof(CharType)) 46 46 CRASH(); 47 m_data = static_cast<CharType*>(fastMalloc(m_length * sizeof(CharType)));47 m_data = adoptPtr(static_cast<CharType*>(fastMalloc(m_length * sizeof(CharType)))); 48 48 } 49 49 50 50 ~StringBuffer() 51 51 { 52 fastFree(m_data);53 52 } 54 53 … … 64 63 if (newLength > std::numeric_limits<unsigned>::max() / sizeof(UChar)) 65 64 CRASH(); 66 m_data = static_cast<UChar*>(fastRealloc(m_data, newLength * sizeof(UChar)));65 m_data = adoptPtr(static_cast<UChar*>(fastRealloc(m_data.release().leakPtr(), newLength * sizeof(UChar)))); 67 66 } 68 67 m_length = newLength; … … 70 69 71 70 unsigned length() const { return m_length; } 72 CharType* characters() { return m_data ; }71 CharType* characters() { return m_data.get(); } 73 72 74 CharType& operator[](unsigned i) { ASSERT_WITH_SECURITY_IMPLICATION(i < m_length); return m_data[i]; } 73 CharType& operator[](unsigned i) 74 { 75 ASSERT_WITH_SECURITY_IMPLICATION(i < m_length); 76 return m_data.get()[i]; 77 } 75 78 76 CharType* release() { CharType* data = m_data; m_data = 0; return data; } 79 PassOwnPtr<CharType> release() 80 { 81 OwnPtr<CharType> data = m_data.release(); 82 return data.release(); 83 } 77 84 78 85 private: 79 86 unsigned m_length; 80 CharType*m_data;87 OwnPtr<CharType> m_data; 81 88 }; 82 89 -
trunk/Source/WTF/wtf/text/StringImpl.h
r154145 r155121 29 29 #include <wtf/Forward.h> 30 30 #include <wtf/MathExtras.h> 31 #include <wtf/PassOwnPtr.h> 31 32 #include <wtf/StdLibExtras.h> 32 33 #include <wtf/StringHasher.h> … … 233 234 234 235 // Create a StringImpl adopting ownership of the provided buffer (BufferOwned) 235 StringImpl( const LChar*characters, unsigned length)236 StringImpl(PassOwnPtr<LChar> characters, unsigned length) 236 237 : m_refCount(s_refCountIncrement) 237 238 , m_length(length) 238 , m_data8(characters )239 , m_data8(characters.leakPtr()) 239 240 , m_buffer(0) 240 241 , m_hashAndFlags(s_hashFlag8BitBuffer | BufferOwned) … … 274 275 275 276 // Create a StringImpl adopting ownership of the provided buffer (BufferOwned) 276 StringImpl( const UChar*characters, unsigned length)277 StringImpl(PassOwnPtr<UChar> characters, unsigned length) 277 278 : m_refCount(s_refCountIncrement) 278 279 , m_length(length) 279 , m_data16(characters )280 , m_data16(characters.leakPtr()) 280 281 , m_buffer(0) 281 282 , m_hashAndFlags(BufferOwned) … … 473 474 if (size > std::numeric_limits<unsigned>::max()) 474 475 CRASH(); 475 return adoptRef(new StringImpl(vector.releaseBuffer() , size));476 return adoptRef(new StringImpl(vector.releaseBuffer().release(), size)); 476 477 } 477 478 return empty(); -
trunk/Source/WebCore/ChangeLog
r155120 r155121 1 2013-09-04 Anders Carlsson <andersca@apple.com> 2 3 Vector::releaseBuffer should return an OwnPtr 4 https://bugs.webkit.org/show_bug.cgi?id=120718 5 6 Reviewed by Andreas Kling. 7 8 Change FormStreamFields::currentData to an OwnPtr. 9 10 * platform/network/cf/FormDataStreamCFNet.cpp: 11 (WebCore::closeCurrentStream): 12 (WebCore::advanceCurrentStream): 13 (WebCore::formCreate): 14 1 15 2013-09-05 Andreas Kling <akling@apple.com> 2 16 -
trunk/Source/WebCore/platform/network/cf/FormDataStreamCFNet.cpp
r149255 r155121 108 108 long long currentStreamRangeLength; 109 109 #endif 110 char*currentData;110 OwnPtr<char> currentData; 111 111 CFReadStreamRef formStream; 112 112 unsigned long long streamLength; … … 125 125 #endif 126 126 } 127 if (form->currentData) { 128 fastFree(form->currentData); 129 form->currentData = 0; 130 } 127 128 form->currentData = nullptr; 131 129 } 132 130 … … 144 142 if (nextInput.m_type == FormDataElement::data) { 145 143 size_t size = nextInput.m_data.size(); 146 char*data = nextInput.m_data.releaseBuffer();147 form->currentStream = CFReadStreamCreateWithBytesNoCopy(0, reinterpret_cast<const UInt8*>(data ), size, kCFAllocatorNull);148 form->currentData = data ;144 OwnPtr<char> data = nextInput.m_data.releaseBuffer(); 145 form->currentStream = CFReadStreamCreateWithBytesNoCopy(0, reinterpret_cast<const UInt8*>(data.get()), size, kCFAllocatorNull); 146 form->currentData = data.release(); 149 147 } else { 150 148 #if ENABLE(BLOB) … … 207 205 newInfo->currentStreamRangeLength = BlobDataItem::toEndOfFile; 208 206 #endif 209 newInfo->currentData = 0;210 207 newInfo->formStream = stream; // Don't retain. That would create a reference cycle. 211 208 newInfo->streamLength = formContext->streamLength;
Note: See TracChangeset
for help on using the changeset viewer.