1 Star 0 Fork 81

Alex Gao/openjdk-1.8.0

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
add-8242842-Avoid-reallocating-name-when-checking-fo.patch 3.14 KB
一键复制 编辑 原始数据 按行查看 历史
DXwangg 提交于 2023-09-26 09:10 . Add feature and bug fix for 8u382
From be90711b32cb79822222d31f258ff4e0f45a616c Mon Sep 17 00:00:00 2001
Date: Thu, 21 Sep 2023 15:24:07 +0800
Subject: add 8242842-Avoid-reallocating-name-when-checking-for-tr
---
.../share/classes/java/util/zip/ZipFile.java | 25 ++++++++++++-------
1 file changed, 16 insertions(+), 9 deletions(-)
diff --git a/jdk/src/share/classes/java/util/zip/ZipFile.java b/jdk/src/share/classes/java/util/zip/ZipFile.java
index 9e854e84d..b6a6c2a48 100644
--- a/jdk/src/share/classes/java/util/zip/ZipFile.java
+++ b/jdk/src/share/classes/java/util/zip/ZipFile.java
@@ -1049,7 +1049,7 @@ class ZipFile implements ZipConstants, Closeable {
return h;
}
- private static final int hash_append(int hash, byte b) {
+ private static final int hashAppend(int hash, byte b) {
return hash * 31 + b;
}
@@ -1267,11 +1267,13 @@ class ZipFile implements ZipConstants, Closeable {
}
int hsh = hashN(name, 0, name.length);
int idx = table[(hsh & 0x7fffffff) % tablelen];
+ boolean appendSlash = false;
/*
* This while loop is an optimization where a double lookup
- * for name and name+/ is being performed. The name char
- * array has enough room at the end to try again with a
- * slash appended if the first table lookup does not succeed.
+ * for name and name+/ is being performed. The name byte
+ * array will be updated with an added slash only if the first
+ * table lookup fails and there is a matching hash value for
+ * name+/.
*/
while(true) {
/*
@@ -1282,6 +1284,11 @@ class ZipFile implements ZipConstants, Closeable {
if (getEntryHash(idx) == hsh) {
// The CEN name must match the specfied one
int pos = getEntryPos(idx);
+ if (appendSlash) {
+ name = Arrays.copyOf(name, name.length + 1);
+ name[name.length - 1] = '/';
+ appendSlash = false;
+ }
if (name.length == CENNAM(cen, pos)) {
boolean matched = true;
int nameoff = pos + CENHDR;
@@ -1302,11 +1309,11 @@ class ZipFile implements ZipConstants, Closeable {
if (!addSlash || name[name.length - 1] == '/') {
return -1;
}
- /* Add slash and try once more */
- name = Arrays.copyOf(name, name.length + 1);
- name[name.length - 1] = '/';
- hsh = hash_append(hsh, (byte)'/');
- //idx = table[hsh % tablelen];
+ // Add a slash to the hash code
+ hsh = hashAppend(hsh, (byte)'/');
+ // If we find a match on the new hash code, we need to append a
+ // slash when comparing
+ appendSlash = true;
idx = table[(hsh & 0x7fffffff) % tablelen];
addSlash = false;
}
--
2.22.0
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/gaoxiang90/openjdk-1.8.0.git
git@gitee.com:gaoxiang90/openjdk-1.8.0.git
gaoxiang90
openjdk-1.8.0
openjdk-1.8.0
master

搜索帮助