]> source.dussan.org Git - poi.git/commitdiff
bug 59958: Add cells on the fly to the evaluation sheet cache on cache miss; patch...
authorJaven O'Neal <onealj@apache.org>
Sun, 11 Sep 2016 02:02:56 +0000 (02:02 +0000)
committerJaven O'Neal <onealj@apache.org>
Sun, 11 Sep 2016 02:02:56 +0000 (02:02 +0000)
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1760213 13f79535-47bb-0310-9956-ffa450edef68

src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFEvaluationSheet.java

index c25dfb5d6cdfeb193707906e2f1427e477611c97..7d9d0286f368cc895d46469cea30a5d98c90d68c 100644 (file)
@@ -67,7 +67,28 @@ final class XSSFEvaluationSheet implements EvaluationSheet {
             }
         }
         
-        return _cellCache.get(new CellKey(rowIndex, columnIndex));
+        final CellKey key = new CellKey(rowIndex, columnIndex);
+        EvaluationCell evalcell = _cellCache.get(key);
+        
+        // If cache is stale, update cache with this one cell
+        // This is a compromise between rebuilding the entire cache
+        // (which would quickly defeat the benefit of the cache)
+        // and not caching at all.
+        // See bug 59958: Add cells on the fly to the evaluation sheet cache on cache miss
+        if (evalcell == null) {
+            XSSFRow row = _xs.getRow(rowIndex);
+            if (row == null) {
+                return null;
+            }
+            XSSFCell cell = row.getCell(columnIndex);
+            if (cell == null) {
+                return null;
+            }
+            evalcell = new XSSFEvaluationCell(cell, this);
+            _cellCache.put(key, evalcell);
+        }
+        
+        return evalcell;
     }
     
     private static class CellKey {