[PATCH] FixA: Reference points facets: the index of the point is stored in the lower 8 bits of the facect index. Why was it search via getIndex()?

Wald Commits scm-commit at wald.intevation.org
Mon Aug 19 22:21:11 CEST 2013


# HG changeset patch
# User Sascha L. Teichmann <teichmann at intevation.de>
# Date 1376943549 -7200
# Node ID 6848c5c8fc2368064559f89ceced1b476c099dff
# Parent  c5ce9812388bcde77d9fe3c154149d0837cf2ca8
FixA: Reference points facets: the index of the point is stored in the lower 8 bits of the facect index. Why was it search via getIndex()?

diff -r c5ce9812388b -r 6848c5c8fc23 artifacts/src/main/java/org/dive4elements/river/artifacts/model/fixings/FixReferenceEventsFacet.java
--- a/artifacts/src/main/java/org/dive4elements/river/artifacts/model/fixings/FixReferenceEventsFacet.java	Mon Aug 19 22:04:03 2013 +0200
+++ b/artifacts/src/main/java/org/dive4elements/river/artifacts/model/fixings/FixReferenceEventsFacet.java	Mon Aug 19 22:19:09 2013 +0200
@@ -76,19 +76,25 @@
         FixResult result = (FixResult) res.getData();
         double currentKm = getCurrentKm(context);
 
-        logger.debug("current km in FRE: " + currentKm);
+        if (logger.isDebugEnabled()) {
+            logger.debug("current km in FRE: " + currentKm);
+        }
 
         KMIndex<QWD []> kmQWs = result.getReferenced();
         KMIndex.Entry<QWD []> kmQWsEntry = kmQWs.binarySearch(currentKm);
-        if (kmQWsEntry != null) {
-            int ndx = index & 255;
-            for (QWD qwd: kmQWsEntry.getValue()) {
-                if (qwd.getIndex() == ndx) {
-                    return qwd;
-                }
-            }
+
+        if (kmQWsEntry == null) {
+            return null;
         }
-        return null;
+
+        // The lower eight bits contain the index of the point.
+        int ndx = index & 255;
+        QWD [] qwds = kmQWsEntry.getValue();
+        if (ndx >= qwds.length) {
+            logger.error("index too large: " + ndx + " " + qwds.length);
+            return null;
+        }
+        return qwds[ndx];
     }
 
 


More information about the Dive4elements-commits mailing list