mirror of
https://github.com/openjdk/jdk.git
synced 2026-05-25 13:04:05 +00:00
8075774: Small readability and performance improvements for zipfs
Reviewed-by: sherman, alanb
This commit is contained in:
parent
8ab93c84ec
commit
33c1f7d181
@ -184,10 +184,19 @@ class ZipConstants {
|
||||
return (LG(b, n)) | (LG(b, n + 4) << 32);
|
||||
}
|
||||
|
||||
static final long GETSIG(byte[] b) {
|
||||
return LG(b, 0);
|
||||
static long getSig(byte[] b, int n) { return LG(b, n); }
|
||||
|
||||
private static boolean pkSigAt(byte[] b, int n, int b1, int b2) {
|
||||
return b[n] == 'P' & b[n + 1] == 'K' & b[n + 2] == b1 & b[n + 3] == b2;
|
||||
}
|
||||
|
||||
static boolean cenSigAt(byte[] b, int n) { return pkSigAt(b, n, 1, 2); }
|
||||
static boolean locSigAt(byte[] b, int n) { return pkSigAt(b, n, 3, 4); }
|
||||
static boolean endSigAt(byte[] b, int n) { return pkSigAt(b, n, 5, 6); }
|
||||
static boolean extSigAt(byte[] b, int n) { return pkSigAt(b, n, 7, 8); }
|
||||
static boolean end64SigAt(byte[] b, int n) { return pkSigAt(b, n, 6, 6); }
|
||||
static boolean locator64SigAt(byte[] b, int n) { return pkSigAt(b, n, 6, 7); }
|
||||
|
||||
// local file (LOC) header fields
|
||||
static final long LOCSIG(byte[] b) { return LG(b, 0); } // signature
|
||||
static final int LOCVER(byte[] b) { return SH(b, 4); } // version needed to extract
|
||||
|
||||
@ -1060,7 +1060,7 @@ class ZipFileSystem extends FileSystem {
|
||||
int pos = 0;
|
||||
int limit = cen.length - ENDHDR;
|
||||
while (pos < limit) {
|
||||
if (CENSIG(cen, pos) != CENSIG)
|
||||
if (!cenSigAt(cen, pos))
|
||||
zerror("invalid CEN header (bad signature)");
|
||||
int method = CENHOW(cen, pos);
|
||||
int nlen = CENNAM(cen, pos);
|
||||
@ -1894,7 +1894,7 @@ class ZipFileSystem extends FileSystem {
|
||||
throws IOException
|
||||
{
|
||||
byte[] cen = zipfs.cen;
|
||||
if (CENSIG(cen, pos) != CENSIG)
|
||||
if (!cenSigAt(cen, pos))
|
||||
zerror("invalid CEN header (bad signature)");
|
||||
versionMade = CENVEM(cen, pos);
|
||||
version = CENVER(cen, pos);
|
||||
@ -2057,9 +2057,9 @@ class ZipFileSystem extends FileSystem {
|
||||
assert (buf.length >= LOCHDR);
|
||||
if (zipfs.readFullyAt(buf, 0, LOCHDR , pos) != LOCHDR)
|
||||
throw new ZipException("loc: reading failed");
|
||||
if (LOCSIG(buf) != LOCSIG)
|
||||
if (!locSigAt(buf, 0))
|
||||
throw new ZipException("loc: wrong sig ->"
|
||||
+ Long.toString(LOCSIG(buf), 16));
|
||||
+ Long.toString(getSig(buf, 0), 16));
|
||||
//startPos = pos;
|
||||
version = LOCVER(buf);
|
||||
flag = LOCFLG(buf);
|
||||
@ -2289,9 +2289,9 @@ class ZipFileSystem extends FileSystem {
|
||||
if (zipfs.readFullyAt(buf, 0, buf.length , locoff)
|
||||
!= buf.length)
|
||||
throw new ZipException("loc: reading failed");
|
||||
if (LOCSIG(buf) != LOCSIG)
|
||||
if (!locSigAt(buf, 0))
|
||||
throw new ZipException("loc: wrong sig ->"
|
||||
+ Long.toString(LOCSIG(buf), 16));
|
||||
+ Long.toString(getSig(buf, 0), 16));
|
||||
|
||||
int locElen = LOCEXT(buf);
|
||||
if (locElen < 9) // EXTT is at lease 9 bytes
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user