Bug 113277 - RefCountedArray needs a size based constructor
Summary: RefCountedArray needs a size based constructor
Status: RESOLVED FIXED
Alias: None
Product: WebKit
Classification: Unclassified
Component: New Bugs (show other bugs)
Version: 528+ (Nightly build)
Hardware: Unspecified Unspecified
: P2 Normal
Assignee: Oliver Hunt
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2013-03-25 23:16 PDT by Oliver Hunt
Modified: 2013-03-26 20:52 PDT (History)
4 users (show)

See Also:


Attachments
Patch (1.63 KB, patch)
2013-03-25 23:23 PDT, Oliver Hunt
no flags Details | Formatted Diff | Diff
Patch (1.69 KB, patch)
2013-03-26 01:50 PDT, Oliver Hunt
benjamin: review+
Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
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>