Skip to content

Commit f2faf49

Browse files
committed
HDDS-14955. Simplify BigInteger instantiation for improved efficiency.
1 parent 8fbe16b commit f2faf49

5 files changed

Lines changed: 5 additions & 6 deletions

File tree

dev-support/pmd/pmd-ruleset.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
<rule ref="category/java/performance.xml/AddEmptyString"/>
4040
<rule ref="category/java/performance.xml/AppendCharacterWithChar" />
4141
<rule ref="category/java/performance.xml/AvoidFileStream"/>
42+
<rule ref="category/java/performance.xml/BigIntegerInstantiation"/>
4243
<rule ref="category/java/performance.xml/InefficientEmptyStringCheck"/>
4344
<rule ref="category/java/performance.xml/InefficientStringBuffering"/>
4445
<rule ref="category/java/performance.xml/StringInstantiation"/>

hadoop-hdds/framework/src/main/java/org/apache/hadoop/hdds/security/x509/certificate/client/DefaultCertificateClient.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -272,9 +272,8 @@ private void updateCachedData(
272272
}
273273

274274
private synchronized void updateCachedRootCAId(String s) {
275-
BigInteger candidateNewId = new BigInteger(s);
276275
if (rootCaCertId == null
277-
|| new BigInteger(rootCaCertId).compareTo(candidateNewId) < 0) {
276+
|| new BigInteger(rootCaCertId).compareTo(new BigInteger(s)) < 0) {
278277
rootCaCertId = s;
279278
}
280279
}

hadoop-hdds/framework/src/main/java/org/apache/hadoop/hdds/security/x509/certificate/utils/SelfSignedCertificate.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ private X509Certificate generateCertificate(BigInteger caCertSerialId) throws Op
117117

118118
BigInteger serial;
119119
if (caCertSerialId == null) {
120-
serial = new BigInteger(Long.toString(Time.monotonicNow()));
120+
serial = BigInteger.valueOf(Time.monotonicNow());
121121
} else {
122122
serial = caCertSerialId;
123123
}

hadoop-hdds/server-scm/src/main/java/org/apache/hadoop/hdds/scm/security/RootCARotationManager.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -378,8 +378,7 @@ public void run() {
378378
CertificateServer newRootCAServer = null;
379379
BigInteger newId = BigInteger.ONE;
380380
try {
381-
newId = new BigInteger(String.valueOf(
382-
sequenceIdGen.getNextId(CERTIFICATE_ID)));
381+
newId = BigInteger.valueOf(sequenceIdGen.getNextId(CERTIFICATE_ID));
383382
newRootCAServer =
384383
HASecurityUtils.initializeRootCertificateServer(secConf,
385384
scm.getCertificateStore(), scmStorageConfig, newId,

hadoop-hdds/server-scm/src/test/java/org/apache/hadoop/hdds/scm/security/TestRootCARotationManager.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ public class TestRootCARotationManager {
9292
private File testDir;
9393
private String cID = UUID.randomUUID().toString();
9494
private String scmID = UUID.randomUUID().toString();
95-
private BigInteger certID = new BigInteger("1");
95+
private BigInteger certID = BigInteger.ONE;
9696

9797
@BeforeEach
9898
public void init() throws IOException, TimeoutException,

0 commit comments

Comments
 (0)