Skip to content

Commit bfa3e33

Browse files
Andreas Buhrtzlaine
authored andcommitted
Reduce compilation time by using SkipParser when determining attribute type.
When using a large parser, the whole tree of parsers in instantiated with the skip (whitespace) parser used. Then, it was instantiated again without a skip parser, just to determine the attribute type. This patch changes the code so the attribute type is determined *with* the skip parser. That way, the number of template instantiations required are halved for some use cases. With gcc 14.2, the instantiations without the skip parser even ended up in the binary. In that case, this patch reduces binary size. This is most likely a compiler bug, as the usage is in decltype().
1 parent 8d7a64f commit bfa3e33

File tree

1 file changed

+7
-7
lines changed

1 file changed

+7
-7
lines changed

include/boost/parser/parser.hpp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -374,7 +374,10 @@ namespace boost { namespace parser {
374374
template<typename T>
375375
using print_type = typename print_t<T>::type;
376376

377-
template<typename R, typename Parser>
377+
struct null_parser
378+
{};
379+
380+
template<typename R, typename Parser, typename SkipParser = null_parser>
378381
struct attribute_impl;
379382

380383
// Utility types.
@@ -1466,9 +1469,6 @@ namespace boost { namespace parser {
14661469
uint32_t(flags::in_apply_parser);
14671470
}
14681471

1469-
struct null_parser
1470-
{};
1471-
14721472
struct skip_skipper
14731473
{
14741474
template<
@@ -2541,7 +2541,7 @@ namespace boost { namespace parser {
25412541
detail::skip(first, last, skip, flags);
25422542
using attr_t = typename detail::attribute_impl<
25432543
BOOST_PARSER_SUBRANGE<std::remove_const_t<Iter>, Sentinel>,
2544-
Parser>::type;
2544+
Parser, SkipParser>::type;
25452545
try {
25462546
attr_t attr_ =
25472547
parser(first, last, context, skip, flags, success);
@@ -9671,7 +9671,7 @@ namespace boost { namespace parser {
96719671
}
96729672

96739673
namespace detail {
9674-
template<typename R, typename Parser>
9674+
template<typename R, typename Parser, typename SkipParser>
96759675
struct attribute_impl
96769676
{
96779677
using parser_type = typename Parser::parser_type;
@@ -9694,7 +9694,7 @@ namespace boost { namespace parser {
96949694
std::declval<iterator &>(),
96959695
std::declval<sentinel>(),
96969696
std::declval<context>(),
9697-
detail::null_parser{},
9697+
SkipParser{},
96989698
detail::flags::gen_attrs,
96999699
std::declval<bool &>()));
97009700
};

0 commit comments

Comments
 (0)