Bug 210415 - [LFC][TFC] Pre-fill columnIntrinsicWidths vector
Summary: [LFC][TFC] Pre-fill columnIntrinsicWidths vector
Status: RESOLVED FIXED
Alias: None
Product: WebKit
Classification: Unclassified
Component: Layout and Rendering (show other bugs)
Version: WebKit Nightly Build
Hardware: Unspecified Unspecified
: P2 Normal
Assignee: zalan
URL:
Keywords: InRadar
Depends on:
Blocks:
 
Reported: 2020-04-12 20:20 PDT by zalan
Modified: 2020-04-13 09:32 PDT (History)
6 users (show)

See Also:


Attachments
Patch (9.40 KB, patch)
2020-04-12 20:41 PDT, zalan
no flags Details | Formatted Diff | Diff
Patch (9.50 KB, patch)
2020-04-13 08:10 PDT, zalan
no flags Details | Formatted Diff | Diff
Patch (9.50 KB, patch)
2020-04-13 08:12 PDT, zalan
no flags Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description zalan 2020-04-12 20:20:53 PDT
it's less error prone than the current append logic.
Comment 1 zalan 2020-04-12 20:41:24 PDT
Created attachment 396252 [details]
Patch
Comment 2 Sam Weinig 2020-04-12 21:03:38 PDT
Comment on attachment 396252 [details]
Patch

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

> Source/WebCore/layout/tableformatting/TableFormattingContext.cpp:281
>      Vector<FormattingContext::IntrinsicWidthConstraints> columnIntrinsicWidths;
> +    columnIntrinsicWidths.fill({ }, columnList.size());

I think this can be slightly more efficient if you use the Vector constructor that takes a size + value to fill:

Vector<FormattingContext::IntrinsicWidthConstraints> columnIntrinsicWidths(columnList.size(), { });

 (or, if std::is_pod<FormattingContext::IntrinsicWidthConstraints>::value is true, you can just pass the size).

> Source/WebCore/layout/tableformatting/TableFormattingContext.cpp:341
>          Vector<ColumnMinimumWidth> columnMinimumWidths;
> +        columnMinimumWidths.fill({ }, columns.size());

Same here.
Comment 3 Sam Weinig 2020-04-12 21:06:04 PDT
(In reply to Sam Weinig from comment #2)
> Comment on attachment 396252 [details]
> Patch
> 
> View in context:
> https://bugs.webkit.org/attachment.cgi?id=396252&action=review
> 
> > Source/WebCore/layout/tableformatting/TableFormattingContext.cpp:281
> >      Vector<FormattingContext::IntrinsicWidthConstraints> columnIntrinsicWidths;
> > +    columnIntrinsicWidths.fill({ }, columnList.size());
> 
> I think this can be slightly more efficient if you use the Vector
> constructor that takes a size + value to fill:
> 
> Vector<FormattingContext::IntrinsicWidthConstraints>
> columnIntrinsicWidths(columnList.size(), { });
> 
>  (or, if std::is_pod<FormattingContext::IntrinsicWidthConstraints>::value is
> true, you can just pass the size).
> 
> > Source/WebCore/layout/tableformatting/TableFormattingContext.cpp:341
> >          Vector<ColumnMinimumWidth> columnMinimumWidths;
> > +        columnMinimumWidths.fill({ }, columns.size());
> 
> Same here.

(yes, it now annoys me that the Vector::fill() and the filling Vector constructor take their arguments in opposite order).
Comment 4 zalan 2020-04-12 21:12:24 PDT
(In reply to Sam Weinig from comment #2)
> Comment on attachment 396252 [details]
> Patch
> 
> View in context:
> https://bugs.webkit.org/attachment.cgi?id=396252&action=review
> 
> > Source/WebCore/layout/tableformatting/TableFormattingContext.cpp:281
> >      Vector<FormattingContext::IntrinsicWidthConstraints> columnIntrinsicWidths;
> > +    columnIntrinsicWidths.fill({ }, columnList.size());
> 
> I think this can be slightly more efficient if you use the Vector
> constructor that takes a size + value to fill:
> 
> Vector<FormattingContext::IntrinsicWidthConstraints>
> columnIntrinsicWidths(columnList.size(), { });
> 
>  (or, if std::is_pod<FormattingContext::IntrinsicWidthConstraints>::value is
> true, you can just pass the size).
> 
> > Source/WebCore/layout/tableformatting/TableFormattingContext.cpp:341
> >          Vector<ColumnMinimumWidth> columnMinimumWidths;
> > +        columnMinimumWidths.fill({ }, columns.size());
> 
> Same here.
Thanks Sam. Yeah, I should have looked at the c'tors (funny side note; whenever I try to use some WTF APIs, someone tells me there's a more efficient way to do it.:)
Comment 5 zalan 2020-04-13 08:10:36 PDT
Created attachment 396277 [details]
Patch
Comment 6 EWS 2020-04-13 08:11:43 PDT
ChangeLog entry in LayoutTests/ChangeLog contains OOPS!.
Comment 7 zalan 2020-04-13 08:12:40 PDT
Created attachment 396279 [details]
Patch
Comment 8 EWS 2020-04-13 08:58:31 PDT
Committed r260009: <https://trac.webkit.org/changeset/260009>

All reviewed patches have been landed. Closing bug and clearing flags on attachment 396279 [details].
Comment 9 Radar WebKit Bug Importer 2020-04-13 08:59:13 PDT
<rdar://problem/61718322>
Comment 10 Sam Weinig 2020-04-13 09:32:51 PDT
(In reply to zalan from comment #4)
> (In reply to Sam Weinig from comment #2)
> > Comment on attachment 396252 [details]
> > Patch
> > 
> > View in context:
> > https://bugs.webkit.org/attachment.cgi?id=396252&action=review
> > 
> > > Source/WebCore/layout/tableformatting/TableFormattingContext.cpp:281
> > >      Vector<FormattingContext::IntrinsicWidthConstraints> columnIntrinsicWidths;
> > > +    columnIntrinsicWidths.fill({ }, columnList.size());
> > 
> > I think this can be slightly more efficient if you use the Vector
> > constructor that takes a size + value to fill:
> > 
> > Vector<FormattingContext::IntrinsicWidthConstraints>
> > columnIntrinsicWidths(columnList.size(), { });
> > 
> >  (or, if std::is_pod<FormattingContext::IntrinsicWidthConstraints>::value is
> > true, you can just pass the size).
> > 
> > > Source/WebCore/layout/tableformatting/TableFormattingContext.cpp:341
> > >          Vector<ColumnMinimumWidth> columnMinimumWidths;
> > > +        columnMinimumWidths.fill({ }, columns.size());
> > 
> > Same here.
> Thanks Sam. Yeah, I should have looked at the c'tors (funny side note;
> whenever I try to use some WTF APIs, someone tells me there's a more
> efficient way to do it.:)

(Alas, we have been adding little optimizations for years here. Admittedly, most are around avoid extra size checks when we know things are uninitialized and who knows if compilers right now might be able to do that for us, but alas, here we are).