Skip to content

Commit

Permalink
Merge pull request #167 from palmin/master
Browse files Browse the repository at this point in the history
use autorelease pool during PGPS2K iteration to reduce peak memory usage
  • Loading branch information
krzyzanowskim committed Nov 30, 2019
2 parents afcaf46 + 1423126 commit 0867be8
Showing 1 changed file with 10 additions and 8 deletions.
18 changes: 10 additions & 8 deletions ObjectivePGP/PGPS2K.m
Expand Up @@ -146,15 +146,17 @@ - (nullable NSData *)buildKeyDataForPassphrase:(NSData *)passphrase prefix:(null
// then iterate
int iterations = 0;
while (iterations * data.length < codedCount) {
let nextTotalLength = (iterations + 1) * data.length;
if (nextTotalLength > codedCount) {
let totalLength = iterations * data.length;
let remainder = [data subdataWithRange:(NSRange){0, codedCount - totalLength}];
update(remainder.bytes, (int)remainder.length);
} else {
update(data.bytes, (int)data.length);
@autoreleasepool {
let nextTotalLength = (iterations + 1) * data.length;
if (nextTotalLength > codedCount) {
let totalLength = iterations * data.length;
let remainder = [data subdataWithRange:(NSRange){0, codedCount - totalLength}];
update(remainder.bytes, (int)remainder.length);
} else {
update(data.bytes, (int)data.length);
}
iterations++;
}
iterations++;
}
};
} break;
Expand Down

0 comments on commit 0867be8

Please sign in to comment.