@@ -430,6 +430,24 @@ auto group_annotations(const sourcemeta::blaze::SimpleOutput &output)
430430 return result;
431431}
432432
433+ // The x-jsonld-* keyword names, pre-hashed for the first-pass dispatch
434+ using namespace std ::string_view_literals;
435+ const auto HASH_ID {sourcemeta::core::JSON::Object::hash (" x-jsonld-id" sv)};
436+ const auto HASH_REVERSE {
437+ sourcemeta::core::JSON::Object::hash (" x-jsonld-reverse" sv)};
438+ const auto HASH_TYPE {sourcemeta::core::JSON::Object::hash (" x-jsonld-type" sv)};
439+ const auto HASH_DATATYPE {
440+ sourcemeta::core::JSON::Object::hash (" x-jsonld-datatype" sv)};
441+ const auto HASH_LANGUAGE {
442+ sourcemeta::core::JSON::Object::hash (" x-jsonld-language" sv)};
443+ const auto HASH_DIRECTION {
444+ sourcemeta::core::JSON::Object::hash (" x-jsonld-direction" sv)};
445+ const auto HASH_JSON {sourcemeta::core::JSON::Object::hash (" x-jsonld-json" sv)};
446+ const auto HASH_GRAPH {sourcemeta::core::JSON::Object::hash (" x-jsonld-graph" sv)};
447+ const auto HASH_CONTAINER {
448+ sourcemeta::core::JSON::Object::hash (" x-jsonld-container" sv)};
449+ const auto HASH_SELF {sourcemeta::core::JSON::Object::hash (" x-jsonld-self" sv)};
450+
433451// Turn the JSON-LD annotations into a resolved map, or the first error found.
434452// The first pass groups the facts by location, the second derives each kind
435453// from the value shape and validates the facts against it
@@ -444,11 +462,13 @@ auto resolve(const sourcemeta::core::JSON &instance,
444462 continue ;
445463 }
446464
447- const auto &keyword{location.evaluate_path .back (). to_property () };
465+ const auto &keyword{location.evaluate_path .back ()};
448466 const auto &instance_location{location.instance_location };
449467
450- if (keyword == " x-jsonld-id" || keyword == " x-jsonld-reverse" ) {
451- const bool reverse{keyword == " x-jsonld-reverse" };
468+ if (keyword.property_equals (" x-jsonld-id" , HASH_ID ) ||
469+ keyword.property_equals (" x-jsonld-reverse" , HASH_REVERSE )) {
470+ const bool reverse{
471+ keyword.property_equals (" x-jsonld-reverse" , HASH_REVERSE )};
452472 for (const auto &value : values) {
453473 if (!is_iri_value (value)) {
454474 return facet_error (
@@ -460,7 +480,7 @@ auto resolve(const sourcemeta::core::JSON &instance,
460480 add_edge (accumulator[instance_location].edges , value.to_string (),
461481 reverse);
462482 }
463- } else if (keyword == " x-jsonld-type" ) {
483+ } else if (keyword. property_equals ( " x-jsonld-type" , HASH_TYPE ) ) {
464484 auto &types{accumulator[instance_location].types };
465485 for (const auto &value : values) {
466486 if (value.is_array ()) {
@@ -479,7 +499,7 @@ auto resolve(const sourcemeta::core::JSON &instance,
479499 add_type (types, value.to_string ());
480500 }
481501 }
482- } else if (keyword == " x-jsonld-datatype" ) {
502+ } else if (keyword. property_equals ( " x-jsonld-datatype" , HASH_DATATYPE ) ) {
483503 for (const auto &value : values) {
484504 if (!is_iri_value (value)) {
485505 return facet_error (
@@ -496,7 +516,7 @@ auto resolve(const sourcemeta::core::JSON &instance,
496516
497517 datatype = value.to_string ();
498518 }
499- } else if (keyword == " x-jsonld-language" ) {
519+ } else if (keyword. property_equals ( " x-jsonld-language" , HASH_LANGUAGE ) ) {
500520 for (const auto &value : values) {
501521 if (!value.is_string () ||
502522 !sourcemeta::core::is_langtag (value.to_string ())) {
@@ -519,7 +539,7 @@ auto resolve(const sourcemeta::core::JSON &instance,
519539 language = value.to_string ();
520540 }
521541 }
522- } else if (keyword == " x-jsonld-direction" ) {
542+ } else if (keyword. property_equals ( " x-jsonld-direction" , HASH_DIRECTION ) ) {
523543 for (const auto &value : values) {
524544 const auto parsed{parse_direction (value)};
525545 if (!parsed.has_value ()) {
@@ -537,7 +557,7 @@ auto resolve(const sourcemeta::core::JSON &instance,
537557
538558 direction = parsed;
539559 }
540- } else if (keyword == " x-jsonld-json" ) {
560+ } else if (keyword. property_equals ( " x-jsonld-json" , HASH_JSON ) ) {
541561 for (const auto &value : values) {
542562 if (!value.is_boolean ()) {
543563 return facet_error (instance_location,
@@ -551,7 +571,7 @@ auto resolve(const sourcemeta::core::JSON &instance,
551571 accumulator[instance_location].json = true ;
552572 }
553573 }
554- } else if (keyword == " x-jsonld-graph" ) {
574+ } else if (keyword. property_equals ( " x-jsonld-graph" , HASH_GRAPH ) ) {
555575 for (const auto &value : values) {
556576 if (!value.is_boolean ()) {
557577 return facet_error (instance_location,
@@ -563,7 +583,7 @@ auto resolve(const sourcemeta::core::JSON &instance,
563583 accumulator[instance_location].graph = true ;
564584 }
565585 }
566- } else if (keyword == " x-jsonld-container" ) {
586+ } else if (keyword. property_equals ( " x-jsonld-container" , HASH_CONTAINER ) ) {
567587 for (const auto &value : values) {
568588 const auto parsed{parse_container (value)};
569589 if (!parsed.has_value ()) {
@@ -581,7 +601,7 @@ auto resolve(const sourcemeta::core::JSON &instance,
581601
582602 container = parsed;
583603 }
584- } else if (keyword == " x-jsonld-self" ) {
604+ } else if (keyword. property_equals ( " x-jsonld-self" , HASH_SELF ) ) {
585605 for (const auto &value : values) {
586606 if (!value.is_string () ||
587607 !sourcemeta::core::URITemplate::is_uritemplate (value.to_string ())) {
0 commit comments