Fix Out of memory for large attachment #115

This commit is contained in:
J-Jamet committed 2018-09-03 20:06:50 +02:00
1 parent bb3fb26847
commit 9130a3851f
7 files changed
+91 -34

No files matched your search

@@ -63,30 +63,36 @@ public class BinaryPool {
@Override
public boolean operate(PwEntryV4 entry) {
for (PwEntryV4 histEntry : entry.getHistory()) {
poolAdd(histEntry.getBinaries());
add(histEntry.getBinaries());
}
poolAdd(entry.getBinaries());
add(entry.getBinaries());
return true;
}
}
private void poolAdd(Map<String, ProtectedBinary> dict) {
private void add(Map<String, ProtectedBinary> dict) {
for (ProtectedBinary pb : dict.values()) {
poolAdd(pb);
add(pb);
}
}
public void poolAdd(ProtectedBinary pb) {
assert(pb != null);
public void add(ProtectedBinary pb) {
assert(pb != null);
if (findKey(pb) != -1) return;
if (poolFind(pb) != -1) return;
pool.put(pool.size(), pb);
pool.put(findUnusedKey(), pb);
}
public int findUnusedKey() {
int unusedKey = pool.size();
while(get(unusedKey) != null)
unusedKey++;
return unusedKey;
}
public int poolFind(ProtectedBinary pb) {
public int findKey(ProtectedBinary pb) {
for (Entry<Integer, ProtectedBinary> pair : pool.entrySet()) {
if (pair.getValue().equals(pb)) return pair.getKey();
}