Add optimization that measures term @id definition once.

This commit is contained in:
Dave Longley 2016-04-23 23:42:38 -04:00
parent 9759c9340d
commit 6b5fba05e5

View file

@ -4695,16 +4695,16 @@ class JsonLdProcessor {
}
// no term or @vocab match, check for possible CURIEs
$iri_len = strlen($iri);
$choice = null;
foreach($active_ctx->mappings as $term => $definition) {
// skip terms with colons, they can't be prefixes
if($definition && $definition->_term_has_colon) {
// skip null definitions and terms with colons, they can't be prefixes
if($definition === null || $definition->_term_has_colon) {
continue;
}
// skip entries with @ids that are not partial matches
if($definition === null ||
$definition->{'@id'} === $iri ||
strpos($iri, $definition->{'@id'}) !== 0) {
if(!($iri_len > $definition->_id_length &&
strpos($iri, $definition->{'@id'}) === 0)) {
continue;
}
@ -4712,7 +4712,7 @@ class JsonLdProcessor {
// 1. it has no mapping, OR
// 2. value is null, which means we're not compacting an @value, AND
// the mapping matches the IRI)
$curie = $term . ':' . substr($iri, strlen($definition->{'@id'}));
$curie = $term . ':' . substr($iri, $definition->_id_length);
$is_usable_curie = (!property_exists($active_ctx->mappings, $curie) ||
($value === null && $active_ctx->mappings->{$curie} &&
$active_ctx->mappings->{$curie}->{'@id'} === $iri));
@ -4990,6 +4990,9 @@ class JsonLdProcessor {
}
}
// optimization to store length of @id once for _compactIri
$mapping->_id_length = strlen($mapping->{'@id'});
// IRI mapping now defined
$defined->{$term} = true;