Improved PKPass.pack to reduce the amount of iterations that gets done

This commit is contained in:
Alexander Cerutti
2022-03-12 19:47:06 +01:00
parent 54ee2fb882
commit 153ad08885

View File

@@ -102,18 +102,16 @@ export default class PKPass extends Bundle {
*/
static pack(...passes: PKPass[]): Bundle {
if (!passes.every((pass) => pass instanceof PKPass)) {
throw new Error(Messages.PACK.INVALID);
}
const buffers = passes.map((pass) => pass.getAsBuffer());
const [bundle, freezeBundle] = Bundle.freezable(
"application/vnd.apple.pkpasses",
);
for (let i = 0; i < buffers.length; i++) {
bundle.addBuffer(`packed-pass-${i + 1}.pkpass`, buffers[i]);
for (let i = 0, pass: PKPass; (pass = passes[i]); i++) {
if (!(pass instanceof PKPass)) {
throw new Error(Messages.PACK.INVALID);
}
bundle.addBuffer(`packed-pass-${i + 1}.pkpass`, pass.getAsBuffer());
}
freezeBundle();