diff --git a/vowpalwabbit/learner.cc b/vowpalwabbit/learner.cc index ff1a02d63be..66a0ce8b884 100644 --- a/vowpalwabbit/learner.cc +++ b/vowpalwabbit/learner.cc @@ -127,6 +127,8 @@ class single_example_handler _context.template process(*ec); } + void process_remaining() {} + private: context_type _context; }; @@ -162,11 +164,7 @@ class multi_example_handler public: multi_example_handler(const context_type context) : _context(context) {} - - ~multi_example_handler() - { - if (!ec_seq.empty()) { _context.template process(ec_seq); } - } + ~multi_example_handler() = default; void on_example(example* ec) { @@ -192,6 +190,15 @@ class multi_example_handler } } + void process_remaining() + { + if (!ec_seq.empty()) + { + _context.template process(ec_seq); + ec_seq.clear(); + } + } + private: context_type _context; multi_ex ec_seq; @@ -235,8 +242,7 @@ template void process_examples(queue_type& examples, handler_type& handler) { example* ec; - - while ((ec = examples.pop()) != nullptr) handler.on_example(ec); + while ((ec = examples.pop()) != nullptr) { handler.on_example(ec); } } template @@ -247,12 +253,14 @@ void generic_driver(ready_examples_queue& examples, context_type& context) using handler_type = multi_example_handler; handler_type handler(context); process_examples(examples, handler); + handler.process_remaining(); } else { using handler_type = single_example_handler; handler_type handler(context); process_examples(examples, handler); + handler.process_remaining(); } drain_examples(context.get_master()); } @@ -282,6 +290,7 @@ void generic_driver_onethread(VW::workspace& all) process_examples(examples_queue, handler); }; parse_dispatch(all, multi_ex_fptr); + handler.process_remaining(); all.l->end_examples(); }