You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by gg...@apache.org on 2022/07/04 13:08:51 UTC

[commons-dbcp] 01/02: Performance: No need for map lookups if we traverse map entries instead of keys.

This is an automated email from the ASF dual-hosted git repository.

ggregory pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/commons-dbcp.git

commit d8b26c642781de7d425469adf7a168ab4433b9a2
Author: Gary Gregory <ga...@gmail.com>
AuthorDate: Mon Jul 4 08:54:00 2022 -0400

    Performance: No need for map lookups if we traverse map entries instead
    of keys.
---
 src/changes/changes.xml                                | 15 +++++++++------
 .../apache/commons/dbcp2/BasicDataSourceFactory.java   | 18 +++++++++---------
 2 files changed, 18 insertions(+), 15 deletions(-)

diff --git a/src/changes/changes.xml b/src/changes/changes.xml
index 248a3e3c..2b430440 100644
--- a/src/changes/changes.xml
+++ b/src/changes/changes.xml
@@ -89,6 +89,15 @@ The <action> type attribute can be add,update,fix,remove.
       <action dev="ggregory" type="fix" due-to="Gary Gregory">
         LifetimeExceededException should extend SQLException.
       </action>
+      <action dev="ggregory" type="fix" due-to="Gary Gregory">
+        Replace Exception with SQLException in some method signatures (preserves binary compatibility, not source).
+      </action>
+      <action dev="ggregory" type="fix" due-to="Gary Gregory">
+        Don't leak Connections when PoolableConnectionFactory.makeObject() fails to create a JMX ObjectName.
+      </action>
+      <action dev="ggregory" type="fix" due-to="SpotBugs, Gary Gregory">
+        Performance: No need for map lookups if we traverse map entries instead of keys.
+      </action>
       <!-- ADD -->
       <action dev="ggregory" type="add" due-to="Gary Gregory">
         Add and use AbandonedTrace#setLastUsed(Instant).
@@ -107,12 +116,6 @@ The <action> type attribute can be add,update,fix,remove.
       <action dev="ggregory" type="add" due-to="Gary Gregory">
         Add Utils.getDisconnectionSqlCodes() and Utils.DISCONNECTION_SQL_CODES.
       </action>
-      <action dev="ggregory" type="add" due-to="Gary Gregory">
-        Replace Exception with SQLException in some method signatures (preserves binary compatibility, not source).
-      </action>
-      <action dev="ggregory" type="add" due-to="Gary Gregory">
-        Don't leak Connections when PoolableConnectionFactory.makeObject() fails to create a JMX ObjectName.
-      </action>
       <!-- UPDATE -->
       <action dev="ggregory" type="update" due-to="Dependabot, Gary Gregory">
         Bump actions/cache from 2.1.6 to 3.0.4 #147, #176.
diff --git a/src/main/java/org/apache/commons/dbcp2/BasicDataSourceFactory.java b/src/main/java/org/apache/commons/dbcp2/BasicDataSourceFactory.java
index 5290a449..b99a8e1b 100644
--- a/src/main/java/org/apache/commons/dbcp2/BasicDataSourceFactory.java
+++ b/src/main/java/org/apache/commons/dbcp2/BasicDataSourceFactory.java
@@ -31,6 +31,7 @@ import java.util.LinkedHashMap;
 import java.util.List;
 import java.util.Locale;
 import java.util.Map;
+import java.util.Map.Entry;
 import java.util.Objects;
 import java.util.Optional;
 import java.util.Properties;
@@ -420,18 +421,18 @@ public class BasicDataSourceFactory implements ObjectFactory {
      *            container for info messages
      */
     private void validatePropertyNames(final Reference ref, final Name name, final List<String> warnMessages,
-            final List<String> infoMessages) {
+        final List<String> infoMessages) {
         final List<String> allPropsAsList = Arrays.asList(ALL_PROPERTIES);
         final String nameString = name != null ? "Name = " + name.toString() + " " : "";
         if (NUPROP_WARNTEXT != null && !NUPROP_WARNTEXT.isEmpty()) {
-            for (final String propertyName : NUPROP_WARNTEXT.keySet()) {
+            for (final Entry<String, String> entry : NUPROP_WARNTEXT.entrySet()) {
+                final String propertyName = entry.getKey();
                 final RefAddr ra = ref.get(propertyName);
                 if (ra != null && !allPropsAsList.contains(ra.getType())) {
                     final StringBuilder stringBuilder = new StringBuilder(nameString);
                     final String propertyValue = Objects.toString(ra.getContent(), null);
-                    stringBuilder.append(NUPROP_WARNTEXT.get(propertyName)).append(" You have set value of \"")
-                            .append(propertyValue).append("\" for \"").append(propertyName)
-                            .append("\" property, which is being ignored.");
+                    stringBuilder.append(entry.getValue()).append(" You have set value of \"").append(propertyValue).append("\" for \"").append(propertyName)
+                        .append("\" property, which is being ignored.");
                     warnMessages.add(stringBuilder.toString());
                 }
             }
@@ -443,12 +444,11 @@ public class BasicDataSourceFactory implements ObjectFactory {
             final String propertyName = ra.getType();
             // If property name is not in the properties list, we haven't warned on it
             // and it is not in the "silent" list, tell user we are ignoring it.
-            if (!(allPropsAsList.contains(propertyName) || NUPROP_WARNTEXT.containsKey(propertyName)
-                    || SILENT_PROPERTIES.contains(propertyName))) {
+            if (!(allPropsAsList.contains(propertyName) || NUPROP_WARNTEXT.containsKey(propertyName) || SILENT_PROPERTIES.contains(propertyName))) {
                 final String propertyValue = Objects.toString(ra.getContent(), null);
                 final StringBuilder stringBuilder = new StringBuilder(nameString);
-                stringBuilder.append("Ignoring unknown property: ").append("value of \"").append(propertyValue)
-                        .append("\" for \"").append(propertyName).append("\" property");
+                stringBuilder.append("Ignoring unknown property: ").append("value of \"").append(propertyValue).append("\" for \"").append(propertyName)
+                    .append("\" property");
                 infoMessages.add(stringBuilder.toString());
             }
         }