LayoutBuilder: Initialize BuilderItem::apply more directly

Also, add some timing information.

Change-Id: I5d38cac9e7ad0afb24504ff521f31d5202268462
Reviewed-by: Jarek Kobus <jaroslaw.kobus@qt.io>
This commit is contained in:
hjk
2024-07-18 10:11:33 +02:00
parent 3e1da5b398
commit 41046c0d44
3 changed files with 46 additions and 13 deletions

View File

@@ -27,18 +27,16 @@ public:
// Property setter // Property setter
template <typename Id, typename Arg> template <typename Id, typename Arg>
BuilderItem(IdAndArg<Id, Arg> && idarg) BuilderItem(IdAndArg<Id, Arg> && idarg)
{ : apply([&idarg](X *x) { doit(x, Id{}, idarg.arg); })
apply = [&idarg](X *x) { doit(x, Id{}, idarg.arg); }; {}
}
// Nested child object // Nested child object
template <typename Inner> template <typename Inner>
BuilderItem(Inner && p) BuilderItem(Inner && p)
{ : apply([&p](X *x) { doit(x, NestId{}, std::forward<Inner>(p)); })
apply = [&p](X *x) { doit(x, NestId{}, std::forward<Inner>(p)); }; {}
}
std::function<void(X *)> apply; const std::function<void(X *)> apply;
}; };
#define QTC_DEFINE_BUILDER_SETTER(name, setter) \ #define QTC_DEFINE_BUILDER_SETTER(name, setter) \

View File

@@ -0,0 +1,37 @@
This is an ad-hoc instruction count to judge the overhead imposed
by Layoutbuilder for
Label ll {
text("World")
};
(1) up to Label::Label
(2) after new Label to up to doit()
(3) tuple stuff in doit up to QLabel::setText parameter construction
With
BuilderItem(IdAndArg<Id, Arg> && idarg)
{
apply = [&idarg](X *x) { doit(x, Id{}, idarg.arg); };
}
(1) (2) + (3) Sum
-O0 547 259 + 802 1608
-O2 24 23 47
With
BuilderItem(IdAndArg<Id, Arg> && idarg)
: apply([&idarg](X *x) { doit(x, Id{}, idarg.arg); })
{}
(1) (2) + (3) Sum
-O2 5 23 28

View File

@@ -61,16 +61,14 @@ public:
// Property setter // Property setter
template <typename Id, typename Arg> template <typename Id, typename Arg>
BuilderItem(IdAndArg<Id, Arg> && idarg) BuilderItem(IdAndArg<Id, Arg> && idarg)
{ : apply([&idarg](X *x) { doit(x, Id{}, idarg.arg); })
apply = [&idarg](X *x) { doit(x, Id{}, idarg.arg); }; {}
}
// Nested child object // Nested child object
template <typename Inner> template <typename Inner>
BuilderItem(Inner && p) BuilderItem(Inner && p)
{ : apply([&p](X *x) { doit(x, NestId{}, std::forward<Inner>(p)); })
apply = [&p](X *x) { doit(x, NestId{}, std::forward<Inner>(p)); }; {}
}
std::function<void(X *)> apply; std::function<void(X *)> apply;
}; };