From 9f461013fbeb5235c0d9c54134b4f24cbb811381 Mon Sep 17 00:00:00 2001 From: Vorticity-Flux Date: Sun, 7 Jun 2015 22:21:45 +0100 Subject: [PATCH] Avoid unnecessary iteration if DerivedLength == iolist_size(Acc) Without this patch call to pbkdf2(MacFunc, Password, Salt, Iterations) takes twice as much time as it should as an extra block is produced just to be immediately discarded. This is true for any call where DerivedLength == HMAC block size. --- src/pbkdf2.erl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/pbkdf2.erl b/src/pbkdf2.erl index dcc66064013..33c255e12e1 100644 --- a/src/pbkdf2.erl +++ b/src/pbkdf2.erl @@ -96,7 +96,7 @@ to_hex([Char | Rest]) -> Key :: binary(). pbkdf2(MacFunc, Password, Salt, Iterations, DerivedLength, BlockIndex, Acc) -> - case iolist_size(Acc) > DerivedLength of + case iolist_size(Acc) >= DerivedLength of true -> <> = iolist_to_binary(lists:reverse(Acc)), Bin;