@@ -344,112 +344,14 @@ bench(
344344
345345// ----------------------------------------------------------
346346
347- class boost_default_impl : public any_impl
347+ class boost_impl : public any_impl
348348{
349- public:
350- boost_default_impl (bool with_file_io, parse_options const & popts)
351- : any_impl(" boost" , true , false , with_file_io, popts)
352- {}
353-
354- clock_type::duration
355- parse (
356- string_view s,
357- std::size_t repeat) const override
358- {
359- auto const start = clock_type::now ();
360- stream_parser p ( {}, get_parse_options () );
361- while (repeat--)
362- {
363- p.reset ();
364- system::error_code ec;
365- p.write (s.data (), s.size (), ec);
366- if (! ec)
367- p.finish (ec);
368- if (! ec)
369- auto jv = p.release ();
370- }
371- return clock_type::now () - start;
372- }
373-
374- clock_type::duration
375- parse (file_item const & fi, std::size_t repeat) const override
376- {
377- auto const start = clock_type::now ();
378- stream_parser p ( {}, get_parse_options () );
379- char s[ BOOST_JSON_STACK_BUFFER_SIZE];
380- while (repeat--)
381- {
382- p.reset ();
383-
384- FILE* f = fopen (fi.name .data (), " rb" );
385-
386- system::error_code ec;
387- while ( true )
388- {
389- std::size_t const sz = fread (s, 1 , sizeof (s), f);
390- if ( ferror (f) )
391- {
392- ec = std::io_errc::stream;
393- break ;
394- }
395-
396- p.write ( s, sz, ec );
397- if ( ec.failed () )
398- break ;
399-
400- if ( feof (f) )
401- break ;
402- }
403-
404- if (! ec)
405- p.finish (ec);
406-
407- if (! ec)
408- auto jv = p.release ();
349+ bool is_pool_;
409350
410- fclose (f);
411- }
412- return clock_type::now () - start;
413- }
414-
415- clock_type::duration
416- serialize (
417- string_view s,
418- std::size_t repeat) const override
419- {
420- auto jv = json::parse (s);
421-
422- auto const start = clock_type::now ();
423- serializer sr;
424- string out;
425- out.reserve (512 );
426- while (repeat--)
427- {
428- sr.reset (&jv);
429- out.clear ();
430- for (;;)
431- {
432- out.grow (sr.read (
433- out.end (),
434- out.capacity () -
435- out.size ()).size ());
436- if (sr.done ())
437- break ;
438- out.reserve (
439- out.capacity () + 1 );
440- }
441- }
442- return clock_type::now () - start;
443- }
444- };
445-
446- // ----------------------------------------------------------
447-
448- class boost_pool_impl : public any_impl
449- {
450351public:
451- boost_pool_impl (bool with_file_io, parse_options const & popts)
452- : any_impl(" boost" , true , true , with_file_io, popts)
352+ boost_impl (bool is_pool, bool with_file_io, parse_options const & popts)
353+ : any_impl(" boost" , true , is_pool, with_file_io, popts)
354+ , is_pool_(is_pool)
453355 {}
454356
455357 clock_type::duration
@@ -462,7 +364,11 @@ class boost_pool_impl : public any_impl
462364 while (repeat--)
463365 {
464366 monotonic_resource mr;
465- p.reset (&mr);
367+ storage_ptr sp;
368+ if ( is_pool_ )
369+ sp = &mr;
370+ p.reset ( std::move (sp) );
371+
466372 system::error_code ec;
467373 p.write (s.data (), s.size (), ec);
468374 if (! ec)
@@ -482,7 +388,10 @@ class boost_pool_impl : public any_impl
482388 while (repeat--)
483389 {
484390 monotonic_resource mr;
485- p.reset (&mr);
391+ storage_ptr sp;
392+ if ( is_pool_ )
393+ sp = &mr;
394+ p.reset ( std::move (sp) );
486395
487396 FILE* f = fopen (fi.name .data (), " rb" );
488397
@@ -521,7 +430,10 @@ class boost_pool_impl : public any_impl
521430 std::size_t repeat) const override
522431 {
523432 monotonic_resource mr;
524- auto jv = json::parse (s, &mr);
433+ storage_ptr sp;
434+ if ( is_pool_ )
435+ sp = &mr;
436+ auto jv = json::parse ( s, std::move (sp) );
525437
526438 auto const start = clock_type::now ();
527439 serializer sr;
@@ -693,9 +605,13 @@ class boost_null_impl : public any_impl
693605
694606class boost_simple_impl : public any_impl
695607{
608+ bool is_pool_;
609+
696610public:
697- boost_simple_impl (bool with_file_io, parse_options const & popts)
698- : any_impl(" boost (convenient)" , true , true , with_file_io, popts)
611+ boost_simple_impl (
612+ bool is_pool, bool with_file_io, parse_options const & popts)
613+ : any_impl(" boost (convenient)" , true , is_pool, with_file_io, popts)
614+ , is_pool_(is_pool)
699615 {}
700616
701617 clock_type::duration
@@ -706,9 +622,13 @@ class boost_simple_impl : public any_impl
706622 auto const start = clock_type::now ();
707623 while (repeat--)
708624 {
709- system::error_code ec;
710625 monotonic_resource mr;
711- auto jv = json::parse ( s, ec, &mr, get_parse_options () );
626+ storage_ptr sp;
627+ if ( is_pool_ )
628+ sp = &mr;
629+
630+ system::error_code ec;
631+ auto jv = json::parse ( s, ec, std::move (sp), get_parse_options () );
712632 (void )jv;
713633 }
714634 return clock_type::now () - start;
@@ -720,10 +640,15 @@ class boost_simple_impl : public any_impl
720640 auto const start = clock_type::now ();
721641 while (repeat--)
722642 {
723- system::error_code ec;
724643 std::ifstream is ( fi.name , std::ios::in | std::ios::binary );
644+
725645 monotonic_resource mr;
726- auto jv = json::parse ( is, ec, &mr, get_parse_options () );
646+ storage_ptr sp;
647+ if ( is_pool_ )
648+ sp = &mr;
649+
650+ system::error_code ec;
651+ auto jv = json::parse ( is, ec, std::move (sp), get_parse_options () );
727652 (void )jv;
728653 }
729654 return clock_type::now () - start;
@@ -734,7 +659,11 @@ class boost_simple_impl : public any_impl
734659 string_view s,
735660 std::size_t repeat) const override
736661 {
737- auto jv = json::parse (s);
662+ monotonic_resource mr;
663+ storage_ptr sp;
664+ if ( is_pool_ )
665+ sp = &mr;
666+ auto jv = json::parse ( s, std::move (sp) );
738667
739668 auto const start = clock_type::now ();
740669 std::string out;
@@ -748,9 +677,13 @@ class boost_simple_impl : public any_impl
748677
749678class boost_operator_impl : public any_impl
750679{
680+ bool is_pool_;
681+
751682public:
752- boost_operator_impl (bool with_file_io, parse_options const & popts)
753- : any_impl(" boost (operators)" , true , true , with_file_io, popts)
683+ boost_operator_impl (
684+ bool is_pool, bool with_file_io, parse_options const & popts)
685+ : any_impl(" boost (operators)" , true , is_pool, with_file_io, popts)
686+ , is_pool_(is_pool)
754687 {}
755688
756689 clock_type::duration
@@ -761,7 +694,11 @@ class boost_operator_impl : public any_impl
761694 while (repeat--)
762695 {
763696 monotonic_resource mr;
764- value jv (&mr);
697+ storage_ptr sp;
698+ if ( is_pool_ )
699+ sp = &mr;
700+
701+ value jv ( std::move (sp) );
765702 is.seekg (0 );
766703 is >> get_parse_options () >> jv;
767704 }
@@ -775,7 +712,11 @@ class boost_operator_impl : public any_impl
775712 while (repeat--)
776713 {
777714 monotonic_resource mr;
778- value jv (&mr);
715+ storage_ptr sp;
716+ if ( is_pool_ )
717+ sp = &mr;
718+
719+ value jv ( std::move (sp) );
779720 std::ifstream is ( fi.name , std::ios::in | std::ios::binary );
780721 is >> get_parse_options () >> jv;
781722 }
@@ -787,7 +728,12 @@ class boost_operator_impl : public any_impl
787728 string_view s,
788729 std::size_t repeat) const override
789730 {
790- auto jv = json::parse (s);
731+ monotonic_resource mr;
732+ storage_ptr sp;
733+ if ( is_pool_ )
734+ sp = &mr;
735+
736+ auto jv = json::parse ( s, std::move (sp) );
791737
792738 auto const start = clock_type::now ();
793739 std::string out;
@@ -1063,47 +1009,36 @@ bool add_impl(impl_list & vi, char kind, char alloc, char io, char num)
10631009 default :
10641010 return false ;
10651011 }
1066- bool with_file_io = io == ' y' ;
1012+ bool const with_file_io = io == ' y' ;
1013+ bool const is_pool = alloc == ' p' ;
10671014
10681015 std::unique_ptr<any_impl const > impl;
10691016 switch ( kind )
10701017 {
10711018 case ' b' :
1072- switch (alloc)
1073- {
1074- case ' p' :
1075- impl = std::make_unique<boost_pool_impl>(with_file_io, popts);
1076- break ;
1077- case ' d' :
1078- impl = std::make_unique<boost_default_impl>(
1079- with_file_io, popts);
1080- break ;
1081- }
1019+ impl = std::make_unique<boost_impl>(is_pool, with_file_io, popts);
10821020 break ;
10831021
10841022 case ' u' :
10851023 impl = std::make_unique<boost_null_impl>(with_file_io, popts);
10861024 break ;
10871025
10881026 case ' s' :
1089- impl = std::make_unique<boost_simple_impl>(with_file_io, popts);
1027+ impl = std::make_unique<boost_simple_impl>(
1028+ is_pool, with_file_io, popts);
10901029 break ;
10911030
10921031 case ' o' :
1093- impl = std::make_unique<boost_operator_impl>(with_file_io, popts);
1032+ impl = std::make_unique<boost_operator_impl>(
1033+ is_pool, with_file_io, popts);
10941034 break ;
10951035
10961036#ifdef BOOST_JSON_HAS_RAPIDJSON
10971037 case ' r' :
1098- switch (alloc)
1099- {
1100- case ' p' :
1101- impl = std::make_unique<rapidjson_memory_impl>(with_file_io);
1102- break ;
1103- case ' d' :
1104- impl = std::make_unique<rapidjson_crt_impl>(with_file_io);
1105- break ;
1106- }
1038+ if (is_pool)
1039+ impl = std::make_unique<rapidjson_memory_impl>(with_file_io);
1040+ else
1041+ impl = std::make_unique<rapidjson_crt_impl>(with_file_io);
11071042 break ;
11081043#endif // BOOST_JSON_HAS_RAPIDJSON
11091044
0 commit comments