Skip to content

Commit

Permalink
GHI-#7 Replace String operations with simple char array assignments
Browse files Browse the repository at this point in the history
  • Loading branch information
arcticicestudio committed Feb 26, 2017
1 parent 8213428 commit 3d814f0
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions src/main/java/com/arcticicestudio/icecore/hashids/Hashids.java
Original file line number Diff line number Diff line change
Expand Up @@ -561,18 +561,18 @@ private static String consistentShuffle(String alphabet, String salt) {
}
final char[] saltChars = salt.toCharArray();
int ascVal, j;
char tmp;
for (int idx = alphabet.length() - 1, v = 0, p = 0; idx > 0; idx--, v++) {
char [] tmpArr = alphabet.toCharArray();
for (int idx = tmpArr.length - 1, v = 0, p = 0; idx > 0; idx--, v++) {
v %= salt.length();
ascVal = (int) saltChars[v];
p += ascVal;
j = (ascVal + v + p) % idx;

tmp = alphabet.charAt(j);
alphabet = alphabet.substring(0, j) + alphabet.charAt(idx) + alphabet.substring(j + 1);
alphabet = alphabet.substring(0, idx) + tmp + alphabet.substring(idx + 1);
char tmp = tmpArr[j];
tmpArr[j] = tmpArr[idx];
tmpArr[idx] = tmp;
}
return alphabet;
return new String(tmpArr);
}

private static String hash(long input, String alphabet) {
Expand Down

0 comments on commit 3d814f0

Please sign in to comment.