@@ -655,6 +655,13 @@ struct ParserState {
655655 // whether the next char is escaped
656656 bool escape_next{ false };
657657
658+ doc::InlineContainer*
659+ make_container ()
660+ {
661+ arena.push_back (std::make_unique<doc::InlineContainer>());
662+ return arena.back ().get ();
663+ }
664+
658665 void
659666 flush_text ()
660667 {
@@ -683,8 +690,7 @@ struct ParserState {
683690 kMaxReserve );
684691 cur->children .reserve (desired);
685692 }
686- arena.push_back (std::make_unique<doc::InlineContainer>());
687- auto * scratch = arena.back ().get ();
693+ auto * scratch = make_container ();
688694 frames.push_back (Frame{
689695 r->kind ,
690696 r,
@@ -1010,23 +1016,21 @@ parse(char const* first, char const* last, doc::InlineContainer& out_root)
10101016 // Markdown link/image openers
10111017 if (c == ' !' && i + 1 < s.size () && s[i + 1 ] == ' [' ) {
10121018 st.flush_text ();
1013- st.arena .push_back (std::make_unique<doc::InlineContainer>());
10141019 st.brackets .push_back (Bracket{
10151020 true ,
10161021 st.cur ,
1017- st.arena . back (). get ()
1022+ st.make_container ()
10181023 });
10191024 st.cur = st.brackets .back ().label ;
10201025 i += 2 ;
10211026 continue ;
10221027 }
10231028 if (c == ' [' ) {
10241029 st.flush_text ();
1025- st.arena .push_back (std::make_unique<doc::InlineContainer>());
10261030 st.brackets .push_back (Bracket{
10271031 false ,
10281032 st.cur ,
1029- st.arena . back (). get ()
1033+ st.make_container ()
10301034 });
10311035 st.cur = st.brackets .back ().label ;
10321036 ++i;
@@ -1072,17 +1076,15 @@ parse(char const* first, char const* last, doc::InlineContainer& out_root)
10721076 } else {
10731077 auto href = html_get_attr (tag->attrs , " href" ).value_or (std::string{});
10741078 st.flush_text ();
1079+ auto * scratch = st.make_container ();
10751080 st.frames .push_back (Frame{
10761081 doc::InlineKind::Link,
10771082 &kHtmlRule ,
10781083 st.cur ,
1079- [&]{
1080- st.arena .push_back (std::make_unique<doc::InlineContainer>());
1081- return st.arena .back ().get ();
1082- }(),
1084+ scratch,
10831085 std::string{}
10841086 });
1085- st.cur = st. frames . back (). scratch ;
1087+ st.cur = scratch;
10861088 st.frames .back ().open_tok = std::move (href); // own the href bytes
10871089 }
10881090 i = tag->end ;
@@ -1098,17 +1100,15 @@ parse(char const* first, char const* last, doc::InlineContainer& out_root)
10981100 }
10991101 } else {
11001102 st.flush_text ();
1103+ auto * scratch = st.make_container ();
11011104 st.frames .push_back (Frame{
11021105 *kind,
11031106 &kHtmlRule ,
11041107 st.cur ,
1105- [&]{
1106- st.arena .push_back (std::make_unique<doc::InlineContainer>());
1107- return st.arena .back ().get ();
1108- }(),
1108+ scratch,
11091109 " <tag>"
11101110 });
1111- st.cur = st. frames . back (). scratch ;
1111+ st.cur = scratch;
11121112 }
11131113 i = tag->end ;
11141114 continue ;
0 commit comments