forked from friendica/php-json-ld
Add optimization that measures term @id definition once.
This commit is contained in:
parent
9759c9340d
commit
6b5fba05e5
15
jsonld.php
15
jsonld.php
|
@ -4695,16 +4695,16 @@ class JsonLdProcessor {
|
||||||
}
|
}
|
||||||
|
|
||||||
// no term or @vocab match, check for possible CURIEs
|
// no term or @vocab match, check for possible CURIEs
|
||||||
|
$iri_len = strlen($iri);
|
||||||
$choice = null;
|
$choice = null;
|
||||||
foreach($active_ctx->mappings as $term => $definition) {
|
foreach($active_ctx->mappings as $term => $definition) {
|
||||||
// skip terms with colons, they can't be prefixes
|
// skip null definitions and terms with colons, they can't be prefixes
|
||||||
if($definition && $definition->_term_has_colon) {
|
if($definition === null || $definition->_term_has_colon) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
// skip entries with @ids that are not partial matches
|
// skip entries with @ids that are not partial matches
|
||||||
if($definition === null ||
|
if(!($iri_len > $definition->_id_length &&
|
||||||
$definition->{'@id'} === $iri ||
|
strpos($iri, $definition->{'@id'}) === 0)) {
|
||||||
strpos($iri, $definition->{'@id'}) !== 0) {
|
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -4712,7 +4712,7 @@ class JsonLdProcessor {
|
||||||
// 1. it has no mapping, OR
|
// 1. it has no mapping, OR
|
||||||
// 2. value is null, which means we're not compacting an @value, AND
|
// 2. value is null, which means we're not compacting an @value, AND
|
||||||
// the mapping matches the IRI)
|
// 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) ||
|
$is_usable_curie = (!property_exists($active_ctx->mappings, $curie) ||
|
||||||
($value === null && $active_ctx->mappings->{$curie} &&
|
($value === null && $active_ctx->mappings->{$curie} &&
|
||||||
$active_ctx->mappings->{$curie}->{'@id'} === $iri));
|
$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
|
// IRI mapping now defined
|
||||||
$defined->{$term} = true;
|
$defined->{$term} = true;
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue