Bug 113277

Summary: RefCountedArray needs a size based constructor
Product: WebKit Reporter: Oliver Hunt <oliver>
Component: New BugsAssignee: Oliver Hunt <oliver>
Status: RESOLVED FIXED    
Severity: Normal CC: benjamin, cmarcelo, ojan.autocc, webkit.review.bot
Priority: P2    
Version: 528+ (Nightly build)   
Hardware: Unspecified   
OS: Unspecified   
Attachments:
Description Flags
Patch
none
Patch benjamin: review+

Description Oliver Hunt 2013-03-25 23:16:55 PDT
RefCountedArray needs a size based constructor
Comment 1 Oliver Hunt 2013-03-25 23:23:58 PDT
Created attachment 195011 [details]
Patch
Comment 2 Benjamin Poulain 2013-03-26 00:25:25 PDT
Comment on attachment 195011 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=195011&action=review

> Source/WTF/wtf/RefCountedArray.h:71
> +        m_data = (static_cast<Header*>(fastMalloc(Header::size() + sizeof(T) * size)))->payload();
> +        Header::fromPayload(m_data)->refCount = 1;
> +        Header::fromPayload(m_data)->length = size;
> +        ASSERT(Header::fromPayload(m_data)->length == size);

You also need to call VectorTypeOperations::initialize() on the new data.

Alternatively, by symmetry with Vector, you could have a reserveInitialCapacity() on RefCountedArray that does not do any initialization.
Comment 3 Oliver Hunt 2013-03-26 01:50:46 PDT
Created attachment 195029 [details]
Patch
Comment 4 Benjamin Poulain 2013-03-26 13:35:50 PDT
Comment on attachment 195029 [details]
Patch

LGTM.
Comment 5 Oliver Hunt 2013-03-26 20:52:45 PDT
Committed r146964: <http://trac.webkit.org/changeset/146964>