Configuration#get return value optimization (jeagles)
Project: http://git-wip-us.apache.org/repos/asf/hadoop/repo Commit: http://git-wip-us.apache.org/repos/asf/hadoop/commit/db2adf35 Tree: http://git-wip-us.apache.org/repos/asf/hadoop/tree/db2adf35 Diff: http://git-wip-us.apache.org/repos/asf/hadoop/diff/db2adf35 Branch: refs/heads/HDFS-9806 Commit: db2adf356a937e4c539b2cf5dccfaf90271cf43e Parents: 858d597 Author: Jonathan Eagles <jeag...@yahoo-inc.com> Authored: Mon Mar 27 12:48:44 2017 -0500 Committer: Jonathan Eagles <jeag...@yahoo-inc.com> Committed: Mon Mar 27 12:48:44 2017 -0500 ---------------------------------------------------------------------- .../org/apache/hadoop/conf/Configuration.java | 52 ++++++++++---------- 1 file changed, 27 insertions(+), 25 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/hadoop/blob/db2adf35/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/conf/Configuration.java ---------------------------------------------------------------------- diff --git a/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/conf/Configuration.java b/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/conf/Configuration.java index 60b0398..ada8b02 100644 --- a/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/conf/Configuration.java +++ b/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/conf/Configuration.java @@ -619,42 +619,44 @@ public class Configuration implements Iterable<Map.Entry<String,String>>, * deprecated key, the value of the deprecated key is set as the value for * the provided property name. * + * @param deprecations deprecation context * @param name the property name * @return the first property in the list of properties mapping * the <code>name</code> or the <code>name</code> itself. */ private String[] handleDeprecation(DeprecationContext deprecations, - String name) { + String name) { if (null != name) { name = name.trim(); } - ArrayList<String > names = new ArrayList<String>(); - if (isDeprecated(name)) { - DeprecatedKeyInfo keyInfo = deprecations.getDeprecatedKeyMap().get(name); - if (keyInfo != null) { - if (!keyInfo.getAndSetAccessed()) { - logDeprecation(keyInfo.getWarningMessage(name)); - } - - for (String newKey : keyInfo.newKeys) { - if (newKey != null) { - names.add(newKey); - } + // Initialize the return value with requested name + String[] names = new String[]{name}; + // Deprecated keys are logged once and an updated names are returned + DeprecatedKeyInfo keyInfo = deprecations.getDeprecatedKeyMap().get(name); + if (keyInfo != null) { + if (!keyInfo.getAndSetAccessed()) { + logDeprecation(keyInfo.getWarningMessage(name)); + } + // Override return value for deprecated keys + names = keyInfo.newKeys; + } + // If there are no overlay values we can return early + Properties overlayProperties = getOverlay(); + if (overlayProperties.isEmpty()) { + return names; + } + // Update properties and overlays with reverse lookup values + for (String n : names) { + String deprecatedKey = deprecations.getReverseDeprecatedKeyMap().get(n); + if (deprecatedKey != null && !overlayProperties.containsKey(n)) { + String deprecatedValue = overlayProperties.getProperty(deprecatedKey); + if (deprecatedValue != null) { + getProps().setProperty(n, deprecatedValue); + overlayProperties.setProperty(n, deprecatedValue); } } } - if(names.size() == 0) { - names.add(name); - } - for(String n : names) { - String deprecatedKey = deprecations.getReverseDeprecatedKeyMap().get(n); - if (deprecatedKey != null && !getOverlay().containsKey(n) && - getOverlay().containsKey(deprecatedKey)) { - getProps().setProperty(n, getOverlay().getProperty(deprecatedKey)); - getOverlay().setProperty(n, getOverlay().getProperty(deprecatedKey)); - } - } - return names.toArray(new String[names.size()]); + return names; } private void handleDeprecation() { --------------------------------------------------------------------- To unsubscribe, e-mail: common-commits-unsubscr...@hadoop.apache.org For additional commands, e-mail: common-commits-h...@hadoop.apache.org