This is an automated email from the ASF dual-hosted git repository. andy pushed a commit to branch main in repository https://gitbox.apache.org/repos/asf/jena.git
commit b2480f49b54a0caaebbb3a39a231f8e992719a63 Author: Andy Seaborne <[email protected]> AuthorDate: Sun Oct 27 20:54:21 2024 +0000 Use simple cache for IRIxResolver --- .../java/org/apache/jena/irix/IRIxResolver.java | 25 ++++++++++++++++------ .../main/java/org/apache/jena/rfc3986/IRI3986.java | 4 ++-- 2 files changed, 20 insertions(+), 9 deletions(-) diff --git a/jena-core/src/main/java/org/apache/jena/irix/IRIxResolver.java b/jena-core/src/main/java/org/apache/jena/irix/IRIxResolver.java index d385cdc058..299d15db73 100644 --- a/jena-core/src/main/java/org/apache/jena/irix/IRIxResolver.java +++ b/jena-core/src/main/java/org/apache/jena/irix/IRIxResolver.java @@ -25,7 +25,11 @@ import org.apache.jena.atlas.lib.Cache; import org.apache.jena.atlas.lib.CacheFactory; /** - * A resolver is a base IRI and a policy for resolution. The policy choices are + * A resolver is a base IRI and a policy for resolution. + * Use of an {@code IRIxResolver} should be from a single thread + * because the {@code IRIxResolver} has a light-weight single thread cache. + * + * The policy choices are * <ul> * <li>whether to resolve against the base, or only consider the IRI being processed</li> * <li>whether to allow relative IRIs after resolving</li> @@ -59,13 +63,23 @@ public class IRIxResolver { /** Return the base of this resolver as a string */ public String getBaseURI() { return base == null ? null : base.str(); } + /** + * Clone an {@code IRIxResolver}. + * This clone may be used on a different thread. + */ + @Override + public IRIxResolver clone() { + return new IRIxResolver(base, resolve, allowRelative); + } + /* - * Some providers are expensive compared to the cost of parsing. + * Resolving IRIs is sufficiently expensive that a cache helps. * During parsing a lot of IRIs are being created, many the same. For example, - * e.g. properties or blocks of triples with the same subject. + * e.g. properties or blocks of triples with the same subject so there is a space + * saving as well. */ private static int DftCacheSize = 500; - private Cache<String, IRIx> cache = CacheFactory.createCache(DftCacheSize); + private Cache<String, IRIx> cache = CacheFactory.createSimpleCache(DftCacheSize); /** Resolve the argument URI string according to resolver policy */ public IRIx resolve(String other) { @@ -75,9 +89,6 @@ public class IRIxResolver { // To allow for exceptions, we try the cache, and if no hit, // make the result then try again to fill the cache. - // Because for a given key there is one right answer, it does not matter - // if any thread gets in and changes the cache (cache operations are - // thread safe). IRIx iri = cache.getIfPresent(other); if ( iri != null ) diff --git a/jena-iri3986/src/main/java/org/apache/jena/rfc3986/IRI3986.java b/jena-iri3986/src/main/java/org/apache/jena/rfc3986/IRI3986.java index 39ce5ef626..973f903c73 100644 --- a/jena-iri3986/src/main/java/org/apache/jena/rfc3986/IRI3986.java +++ b/jena-iri3986/src/main/java/org/apache/jena/rfc3986/IRI3986.java @@ -88,14 +88,14 @@ import java.util.regex.Pattern; * * <pre> * IRI3986 base = ... - * RFC3986 iri = RFC3986.create(string); + * IRI3986 iri = RFC3986.create(string); * IRI3986 iri2 = iri.resolve(base); * </pre> * * Normalize: * * <pre> - * RFC3986 base = ... + * IRI3986 base = ... * IRI3986 iri = RFC3986.create(string); * IRI3986 iri2 = iri.normalize(); * </pre>
