Bug 164952 - Use Vector::uncheckedAppend() in more places
Summary: Use Vector::uncheckedAppend() in more places
Status: RESOLVED FIXED
Alias: None
Product: WebKit
Classification: Unclassified
Component: WebCore Misc. (show other bugs)
Version: WebKit Nightly Build
Hardware: All All
: P2 Normal
Assignee: Daniel Bates
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2016-11-18 13:46 PST by Daniel Bates
Modified: 2016-12-06 09:43 PST (History)
0 users

See Also:


Attachments
Patch (14.05 KB, patch)
2016-11-18 13:47 PST, Daniel Bates
darin: review+
Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Daniel Bates 2016-11-18 13:46:36 PST
We can use Vector::uncheckedAppend() whenever the number of items that will be appended to a vector is equal to or less than its capacity. Many call sites that call Vector::reserveInitialCapacity() and then use Vector::append() can be written to use Vector::uncheckedAppend().
Comment 1 Daniel Bates 2016-11-18 13:47:59 PST
Created attachment 295187 [details]
Patch
Comment 2 Darin Adler 2016-11-20 16:29:59 PST
Comment on attachment 295187 [details]
Patch

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

> Source/WebCore/contentextensions/DFAMinimizer.cpp:90
> +        m_sets.uncheckedAppend(SetDescriptor({ 0, size, 0 }));

Peculiar that we reserve capacity for "size" elements, but here we do only a single uncheckedAppend. Did we reserve too much capacity?

Syntax is peculiar; I think it should just be:

    m_sets.uncheckedAppend(SetDescriptor { 0, size, 0 });

No need to have both parentheses and braces.
Comment 3 Daniel Bates 2016-12-06 09:39:30 PST
(In reply to comment #2)
> Comment on attachment 295187 [details]
> Patch
> 
> View in context:
> https://bugs.webkit.org/attachment.cgi?id=295187&action=review
> 
> > Source/WebCore/contentextensions/DFAMinimizer.cpp:90
> > +        m_sets.uncheckedAppend(SetDescriptor({ 0, size, 0 }));
> 
> Peculiar that we reserve capacity for "size" elements, but here we do only a
> single uncheckedAppend. Did we reserve too much capacity?
> 

We may have reserved too much though it is not immediately obvious from reading the code. I hope you do not mind that I defer proving the bound of m_set to bug #165472.

> Syntax is peculiar; I think it should just be:
> 
>     m_sets.uncheckedAppend(SetDescriptor { 0, size, 0 });
> 
> No need to have both parentheses and braces.

Will fix before landing.
Comment 4 Daniel Bates 2016-12-06 09:43:10 PST
Committed r209400: <http://trac.webkit.org/changeset/209400>