8170831: ZipFile implementation no longer caches the last accessed entry/pos
Reviewed-by: psandoz
--- a/jdk/src/java.base/share/classes/java/util/zip/ZipFile.java Wed Nov 30 19:40:36 2016 -0800
+++ b/jdk/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;
}