Skip to content

Commit 713e274

Browse files
samuelscheitLinusU
authored andcommitted
🎉 Improve Android performance by caching SecureRandom
1 parent d5b9996 commit 713e274

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

android/src/main/java/org/linusu/RNGetRandomValuesModule.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111
public class RNGetRandomValuesModule extends NativeRNGetRandomValuesSpec {
1212
protected static final String NAME = "RNGetRandomValues";
1313

14+
private static final SecureRandom SECURE_RANDOM = new SecureRandom();
15+
1416
public RNGetRandomValuesModule(ReactApplicationContext reactContext) {
1517
super(reactContext);
1618
}
@@ -23,9 +25,8 @@ public String getName() {
2325
@Override
2426
public String getRandomBase64(double byteLength) {
2527
byte[] data = new byte[(int) byteLength];
26-
SecureRandom random = new SecureRandom();
2728

28-
random.nextBytes(data);
29+
SECURE_RANDOM.nextBytes(data);
2930

3031
return Base64.encodeToString(data, Base64.NO_WRAP);
3132
}

0 commit comments

Comments
 (0)