From 84b232103c5eb49b660f142662cdfa6b0ddec25b Mon Sep 17 00:00:00 2001 From: alexmojaki Date: Tue, 5 Apr 2016 14:55:25 +0200 Subject: [PATCH] Use faster StringBuilder instead of StringBuffer From the `StringBuffer` docs: > As of release JDK 5, this class has been supplemented with an equivalent class designed for use by a single thread, StringBuilder. The StringBuilder class should generally be used in preference to this one, as it supports all of the same operations but it is faster, as it performs no synchronization. Unless you want to support really old versions of Java or share buffers between threads (neither of which seem to be the case here), use `StringBuilder`. --- src/main/java/org/mindrot/BCrypt.java | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/main/java/org/mindrot/BCrypt.java b/src/main/java/org/mindrot/BCrypt.java index 188193f..2427771 100644 --- a/src/main/java/org/mindrot/BCrypt.java +++ b/src/main/java/org/mindrot/BCrypt.java @@ -388,7 +388,7 @@ public class BCrypt { private static String encode_base64(byte d[], int len) throws IllegalArgumentException { int off = 0; - StringBuffer rs = new StringBuffer(); + StringBuilder rs = new StringBuilder(); int c1, c2; if (len <= 0 || len > d.length) @@ -441,7 +441,7 @@ private static byte char64(char x) { */ private static byte[] decode_base64(String s, int maxolen) throws IllegalArgumentException { - StringBuffer rs = new StringBuffer(); + StringBuilder rs = new StringBuilder(); int off = 0, slen = s.length(), olen = 0; byte ret[]; byte c1, c2, c3, c4, o; @@ -654,7 +654,7 @@ public static String hashpw(String password, String salt) { byte passwordb[], saltb[], hashed[]; char minor = (char)0; int rounds, off = 0; - StringBuffer rs = new StringBuffer(); + StringBuilder rs = new StringBuilder(); if (salt.charAt(0) != '$' || salt.charAt(1) != '2') throw new IllegalArgumentException ("Invalid salt version"); @@ -712,7 +712,7 @@ public static String hashpw(String password, String salt) { * @return an encoded salt value */ public static String gensalt(int log_rounds, SecureRandom random) { - StringBuffer rs = new StringBuffer(); + StringBuilder rs = new StringBuilder(); byte rnd[] = new byte[BCRYPT_SALT_LEN]; random.nextBytes(rnd);