You are viewing a plain text version of this content. The canonical link for it is here.
Posted to pr@jena.apache.org by GitBox <gi...@apache.org> on 2022/08/02 08:31:10 UTC

[GitHub] [jena] LorenzBuehmann commented on a diff in pull request #1235: [JENA-2311] query rewrite index does too expensive caching on geo literals

LorenzBuehmann commented on code in PR #1235:
URL: https://github.com/apache/jena/pull/1235#discussion_r935269034


##########
jena-geosparql/src/main/java/org/apache/jena/geosparql/implementation/index/GeometryLiteralIndex.java:
##########
@@ -60,17 +60,15 @@ private static GeometryWrapper retrieveMemoryIndex(String geometryLiteral, Geome
 
         if (INDEX_ACTIVE) {
 
-            if (index.containsKey(geometryLiteral)) {
-                geometryWrapper = index.get(geometryLiteral);
-            } else {
-                if (otherIndex.containsKey(geometryLiteral)) {
-                    geometryWrapper = otherIndex.get(geometryLiteral);
-                } else {
+            geometryWrapper = index.get(geometryLiteral);
+            if (geometryWrapper == null) {
+                geometryWrapper = otherIndex.get(geometryLiteral);
+                if (geometryWrapper == null) {
                     geometryWrapper = geometryDatatype.read(geometryLiteral);
                 }
                 index.put(geometryLiteral, geometryWrapper);
             }

Review Comment:
   True, my bad - should be `computeIfAbsent` to avoid unnecessary lookup of secondary index - so more like
   ``` java
   geometryWrapper = index.computeIfAbsent(geometryLiteral, (lit) -> otherIndex.getOrDefault(lit, geometryDatatype.read(lit)));
   ```
   would this be more readable? Don't know. Technically this is still more efficient from a Java internals point of view as it gathers the internal map bucket just once. But I don't think it matters in our case



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: pr-unsubscribe@jena.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: pr-unsubscribe@jena.apache.org
For additional commands, e-mail: pr-help@jena.apache.org