Optimize SystemEnvironmentPropertyMapper

See gh-21523
This commit is contained in:
dreis2211 2020-06-05 16:03:03 -07:00 committed by Phillip Webb
parent f8d6d9a4b0
commit 0378de7b30
1 changed files with 11 additions and 2 deletions

View File

@ -116,6 +116,16 @@ final class SystemEnvironmentPropertyMapper implements PropertyMapper {
if (!hasDashedEntries(name)) {
return false;
}
StringBuilder legacyCompatibleName = buildLegacyCompatibleName(name);
try {
return ConfigurationPropertyName.of(legacyCompatibleName).isAncestorOf(candidate);
}
catch (Exception ex) {
return false;
}
}
private StringBuilder buildLegacyCompatibleName(ConfigurationPropertyName name) {
StringBuilder legacyCompatibleName = new StringBuilder();
for (int i = 0; i < name.getNumberOfElements(); i++) {
if (i != 0) {
@ -123,8 +133,7 @@ final class SystemEnvironmentPropertyMapper implements PropertyMapper {
}
legacyCompatibleName.append(name.getElement(i, Form.DASHED).replace('-', '.'));
}
return ConfigurationPropertyName.isValid(legacyCompatibleName)
&& ConfigurationPropertyName.of(legacyCompatibleName).isAncestorOf(candidate);
return legacyCompatibleName;
}
boolean hasDashedEntries(ConfigurationPropertyName name) {