@@ -4695,24 +4695,24 @@ protected function _compactIri(
4695
4695
}
4696
4696
4697
4697
// no term or @vocab match, check for possible CURIEs
4698
+ $ iri_len = strlen ($ iri );
4698
4699
$ choice = null ;
4699
4700
foreach ($ active_ctx ->mappings as $ term => $ definition ) {
4700
- // skip terms with colons, they can't be prefixes
4701
- if ($ definition && $ definition ->_term_has_colon ) {
4701
+ // skip null definitions and terms with colons, they can't be prefixes
4702
+ if ($ definition === null || $ definition ->_term_has_colon ) {
4702
4703
continue ;
4703
4704
}
4704
4705
// skip entries with @ids that are not partial matches
4705
- if ($ definition === null ||
4706
- $ definition ->{'@id ' } === $ iri ||
4707
- strpos ($ iri , $ definition ->{'@id ' }) !== 0 ) {
4706
+ if (!($ iri_len > $ definition ->_id_length &&
4707
+ strpos ($ iri , $ definition ->{'@id ' }) === 0 )) {
4708
4708
continue ;
4709
4709
}
4710
4710
4711
4711
// a CURIE is usable if:
4712
4712
// 1. it has no mapping, OR
4713
4713
// 2. value is null, which means we're not compacting an @value, AND
4714
4714
// the mapping matches the IRI)
4715
- $ curie = $ term . ': ' . substr ($ iri , strlen ( $ definition ->{ ' @id ' }) );
4715
+ $ curie = $ term . ': ' . substr ($ iri , $ definition ->_id_length );
4716
4716
$ is_usable_curie = (!property_exists ($ active_ctx ->mappings , $ curie ) ||
4717
4717
($ value === null && $ active_ctx ->mappings ->{$ curie } &&
4718
4718
$ active_ctx ->mappings ->{$ curie }->{'@id ' } === $ iri ));
@@ -4990,6 +4990,9 @@ protected function _createTermDefinition(
4990
4990
}
4991
4991
}
4992
4992
4993
+ // optimization to store length of @id once for _compactIri
4994
+ $ mapping ->_id_length = strlen ($ mapping ->{'@id ' });
4995
+
4993
4996
// IRI mapping now defined
4994
4997
$ defined ->{$ term } = true ;
4995
4998
0 commit comments