Skip to content

Commit 5d30de3

Browse files
committed
Add optimization that caches presence of colon in term.
1 parent a10270f commit 5d30de3

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

js/jsonld.js

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5561,12 +5561,12 @@ function _compactIri(activeCtx, iri, value, relativeTo, reverse) {
55615561
// no term or @vocab match, check for possible CURIEs
55625562
var choice = null;
55635563
for(var term in activeCtx.mappings) {
5564+
var definition = activeCtx.mappings[term];
55645565
// skip terms with colons, they can't be prefixes
5565-
if(term.indexOf(':') !== -1) {
5566+
if(definition && definition._termHasColon) {
55665567
continue;
55675568
}
55685569
// skip entries with @ids that are not partial matches
5569-
var definition = activeCtx.mappings[term];
55705570
if(!definition ||
55715571
definition['@id'] === iri || iri.indexOf(definition['@id']) !== 0) {
55725572
continue;
@@ -5808,10 +5808,14 @@ function _createTermDefinition(activeCtx, localCtx, term, defined) {
58085808
}
58095809
}
58105810

5811+
// always compute whether term has a colon as an optimization for
5812+
// _compactIri
5813+
var colon = term.indexOf(':');
5814+
mapping._termHasColon = (colon !== -1);
5815+
58115816
if(!('@id' in mapping)) {
58125817
// see if the term has a prefix
5813-
var colon = term.indexOf(':');
5814-
if(colon !== -1) {
5818+
if(mapping._termHasColon) {
58155819
var prefix = term.substr(0, colon);
58165820
if(prefix in localCtx) {
58175821
// define parent prefix

0 commit comments

Comments
 (0)