@@ -376,15 +376,14 @@ auto compiler_draft4_validation_type(const Context &context,
376376 return {};
377377 }
378378
379+ ValueTypes types{};
380+ types.set (static_cast <std::uint8_t >(sourcemeta::core::JSON::Type::Real));
381+ types.set (
382+ static_cast <std::uint8_t >(sourcemeta::core::JSON::Type::Integer));
383+ types.set (
384+ static_cast <std::uint8_t >(sourcemeta::core::JSON::Type::Decimal));
379385 return {make (sourcemeta::blaze::InstructionIndex::AssertionTypeStrictAny,
380- context, schema_context, dynamic_context,
381- static_cast <ValueTypes>(
382- (1U << static_cast <std::uint8_t >(
383- sourcemeta::core::JSON::Type::Real)) |
384- (1U << static_cast <std::uint8_t >(
385- sourcemeta::core::JSON::Type::Integer)) |
386- (1U << static_cast <std::uint8_t >(
387- sourcemeta::core::JSON::Type::Decimal))))};
386+ context, schema_context, dynamic_context, types)};
388387 } else if (type == " integer" ) {
389388 if (context.mode == Mode::FastValidation &&
390389 schema_context.schema .defines (" enum" ) &&
@@ -457,15 +456,14 @@ auto compiler_draft4_validation_type(const Context &context,
457456 context, schema_context, dynamic_context,
458457 sourcemeta::core::JSON::Type::Array)};
459458 } else if (type == " number" ) {
459+ ValueTypes types{};
460+ types.set (static_cast <std::uint8_t >(sourcemeta::core::JSON::Type::Real));
461+ types.set (
462+ static_cast <std::uint8_t >(sourcemeta::core::JSON::Type::Integer));
463+ types.set (
464+ static_cast <std::uint8_t >(sourcemeta::core::JSON::Type::Decimal));
460465 return {make (sourcemeta::blaze::InstructionIndex::AssertionTypeStrictAny,
461- context, schema_context, dynamic_context,
462- static_cast <ValueTypes>(
463- (1U << static_cast <std::uint8_t >(
464- sourcemeta::core::JSON::Type::Real)) |
465- (1U << static_cast <std::uint8_t >(
466- sourcemeta::core::JSON::Type::Integer)) |
467- (1U << static_cast <std::uint8_t >(
468- sourcemeta::core::JSON::Type::Decimal))))};
466+ context, schema_context, dynamic_context, types)};
469467 } else if (type == " integer" ) {
470468 return {make (sourcemeta::blaze::InstructionIndex::AssertionTypeStrict,
471469 context, schema_context, dynamic_context,
@@ -478,40 +476,40 @@ auto compiler_draft4_validation_type(const Context &context,
478476 return {};
479477 }
480478 } else if (schema_context.schema .at (dynamic_context.keyword ).is_array ()) {
481- ValueTypes types{0 };
479+ ValueTypes types{};
482480 for (const auto &type :
483481 schema_context.schema .at (dynamic_context.keyword ).as_array ()) {
484482 assert (type.is_string ());
485483 const auto &type_string{type.to_string ()};
486484 if (type_string == " null" ) {
487- types |= ( 1U << static_cast <std:: uint8_t > (
488- sourcemeta::core::JSON::Type::Null));
485+ types. set (
486+ static_cast <std:: uint8_t >( sourcemeta::core::JSON::Type::Null));
489487 } else if (type_string == " boolean" ) {
490- types |= ( 1U << static_cast <std:: uint8_t > (
491- sourcemeta::core::JSON::Type::Boolean));
488+ types. set (
489+ static_cast <std:: uint8_t >( sourcemeta::core::JSON::Type::Boolean));
492490 } else if (type_string == " object" ) {
493- types |= ( 1U << static_cast <std:: uint8_t > (
494- sourcemeta::core::JSON::Type::Object));
491+ types. set (
492+ static_cast <std:: uint8_t >( sourcemeta::core::JSON::Type::Object));
495493 } else if (type_string == " array" ) {
496- types |= ( 1U << static_cast <std:: uint8_t > (
497- sourcemeta::core::JSON::Type::Array));
494+ types. set (
495+ static_cast <std:: uint8_t >( sourcemeta::core::JSON::Type::Array));
498496 } else if (type_string == " number" ) {
499- types |= ( 1U << static_cast <std:: uint8_t > (
500- sourcemeta::core::JSON::Type::Integer));
501- types |= ( 1U << static_cast <std:: uint8_t > (
502- sourcemeta::core::JSON::Type::Real));
503- types |= ( 1U << static_cast <std:: uint8_t > (
504- sourcemeta::core::JSON::Type::Decimal));
497+ types. set (
498+ static_cast <std:: uint8_t >( sourcemeta::core::JSON::Type::Integer));
499+ types. set (
500+ static_cast <std:: uint8_t >( sourcemeta::core::JSON::Type::Real));
501+ types. set (
502+ static_cast <std:: uint8_t >( sourcemeta::core::JSON::Type::Decimal));
505503 } else if (type_string == " integer" ) {
506- types |= ( 1U << static_cast <std:: uint8_t > (
507- sourcemeta::core::JSON::Type::Integer));
504+ types. set (
505+ static_cast <std:: uint8_t >( sourcemeta::core::JSON::Type::Integer));
508506 } else if (type_string == " string" ) {
509- types |= ( 1U << static_cast <std:: uint8_t > (
510- sourcemeta::core::JSON::Type::String));
507+ types. set (
508+ static_cast <std:: uint8_t >( sourcemeta::core::JSON::Type::String));
511509 }
512510 }
513511
514- assert (types != 0 );
512+ assert (types. any () );
515513 return {make (sourcemeta::blaze::InstructionIndex::AssertionTypeStrictAny,
516514 context, schema_context, dynamic_context, types)};
517515 }
@@ -720,13 +718,13 @@ auto compiler_draft4_applicator_anyof(const Context &context,
720718 sourcemeta::blaze::InstructionIndex::
721719 AssertionTypeStrictAny);
722720 })) {
723- ValueTypes types{0 };
721+ ValueTypes types{};
724722 for (const auto &instruction : disjunctors) {
725723 if (instruction.children .front ().type ==
726724 sourcemeta::blaze::InstructionIndex::AssertionTypeStrict) {
727725 const auto &value{
728726 *std::get_if<ValueType>(&instruction.children .front ().value )};
729- types |= ( 1U << static_cast <std::uint8_t >(value));
727+ types. set ( static_cast <std::uint8_t >(value));
730728 }
731729
732730 if (instruction.children .front ().type ==
@@ -737,18 +735,18 @@ auto compiler_draft4_applicator_anyof(const Context &context,
737735 }
738736 }
739737
740- assert (types != 0 );
741- std::uint8_t popcount{0 };
742- for (std::uint8_t temp{types}; temp != 0 ; temp >>= 1 ) {
743- popcount += (temp & 1 );
744- }
738+ assert (types.any ());
739+ const auto popcount{types.count ()};
745740 if (popcount > 1 ) {
746741 return {make (sourcemeta::blaze::InstructionIndex::AssertionTypeStrictAny,
747742 context, schema_context, dynamic_context, types)};
748743 } else {
749744 std::uint8_t type_index{0 };
750- for (std::uint8_t temp{types}; (temp & 1 ) == 0 ; temp >>= 1 ) {
751- type_index++;
745+ for (std::uint8_t bit{0 }; bit < 8 ; bit++) {
746+ if (types.test (bit)) {
747+ type_index = bit;
748+ break ;
749+ }
752750 }
753751 return {make (sourcemeta::blaze::InstructionIndex::AssertionTypeStrict,
754752 context, schema_context, dynamic_context,
0 commit comments