changeset 16218:5689c7c6c075

8170831: ZipFile implementation no longer caches the last accessed entry/pos Reviewed-by: psandoz
author sherman
date Wed, 07 Dec 2016 11:53:26 -0800
parents 54378adce7f1
children 78a9122885d1
files src/java.base/share/classes/java/util/zip/ZipFile.java
diffstat 1 files changed, 8 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/src/java.base/share/classes/java/util/zip/ZipFile.java	Wed Nov 30 19:40:36 2016 -0800
+++ b/src/java.base/share/classes/java/util/zip/ZipFile.java	Wed Dec 07 11:53:26 2016 -0800
@@ -331,7 +331,9 @@
         ZipFileInputStream in = null;
         synchronized (this) {
             ensureOpen();
-            if (!zc.isUTF8() && (entry.flag & EFS) != 0) {
+            if (Objects.equals(lastEntryName, entry.name)) {
+                pos = lastEntryPos;
+            } else if (!zc.isUTF8() && (entry.flag & EFS) != 0) {
                 pos = zsrc.getEntryPos(zc.getBytesUTF8(entry.name), false);
             } else {
                 pos = zsrc.getEntryPos(zc.getBytes(entry.name), false);
@@ -526,6 +528,9 @@
                         Spliterator.IMMUTABLE | Spliterator.NONNULL), false);
     }
 
+    private String lastEntryName;
+    private int lastEntryPos;
+
     /* Checks ensureOpen() before invoke this method */
     private ZipEntry getZipEntry(String name, byte[] bname, int pos) {
         byte[] cen = zsrc.cen;
@@ -563,6 +568,8 @@
                 e.comment = zc.toString(cen, start, clen);
             }
         }
+        lastEntryName = e.name;
+        lastEntryPos = pos;
         return e;
     }