Skip to content

Commit 49ff4b7

Browse files
committed
Merge branch 'gh-15760'
Closes gh-15760
2 parents e2532e1 + 47b378e commit 49ff4b7

File tree

1 file changed

+23
-8
lines changed

1 file changed

+23
-8
lines changed

spring-boot-project/spring-boot/src/main/java/org/springframework/boot/context/properties/source/ConfigurationPropertyName.java

Lines changed: 23 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2018 the original author or authors.
2+
* Copyright 2012-2019 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -195,7 +195,7 @@ public ConfigurationPropertyName append(String elementValue) {
195195
if (elementValue == null) {
196196
return this;
197197
}
198-
Elements additionalElements = of(elementValue).elements;
198+
Elements additionalElements = probablySingleElementOf(elementValue);
199199
return new ConfigurationPropertyName(this.elements.append(additionalElements));
200200
}
201201

@@ -373,8 +373,9 @@ private String buildToString() {
373373
ElementType.DASHED)) {
374374
return this.elements.getSource().toString();
375375
}
376-
StringBuilder result = new StringBuilder();
377-
for (int i = 0; i < getNumberOfElements(); i++) {
376+
int elements = getNumberOfElements();
377+
StringBuilder result = new StringBuilder(elements * 8);
378+
for (int i = 0; i < elements; i++) {
378379
boolean indexed = isIndexed(i);
379380
if (result.length() > 0 && !indexed) {
380381
result.append('.');
@@ -420,12 +421,26 @@ public static ConfigurationPropertyName of(CharSequence name) {
420421
* {@code returnNullIfInvalid} is {@code false}
421422
*/
422423
static ConfigurationPropertyName of(CharSequence name, boolean returnNullIfInvalid) {
424+
Elements elements = elementsOf(name, returnNullIfInvalid);
425+
return (elements != null) ? new ConfigurationPropertyName(elements) : null;
426+
}
427+
428+
private static Elements probablySingleElementOf(CharSequence name) {
429+
return elementsOf(name, false, 1);
430+
}
431+
432+
private static Elements elementsOf(CharSequence name, boolean returnNullIfInvalid) {
433+
return elementsOf(name, returnNullIfInvalid, ElementsParser.DEFAULT_CAPACITY);
434+
}
435+
436+
private static Elements elementsOf(CharSequence name, boolean returnNullIfInvalid,
437+
int parserCapacity) {
423438
if (name == null) {
424439
Assert.isTrue(returnNullIfInvalid, "Name must not be null");
425440
return null;
426441
}
427442
if (name.length() == 0) {
428-
return EMPTY;
443+
return Elements.EMPTY;
429444
}
430445
if (name.charAt(0) == '.' || name.charAt(name.length() - 1) == '.') {
431446
if (returnNullIfInvalid) {
@@ -434,7 +449,7 @@ static ConfigurationPropertyName of(CharSequence name, boolean returnNullIfInval
434449
throw new InvalidConfigurationPropertyNameException(name,
435450
Collections.singletonList('.'));
436451
}
437-
Elements elements = new ElementsParser(name, '.').parse();
452+
Elements elements = new ElementsParser(name, '.', parserCapacity).parse();
438453
for (int i = 0; i < elements.getSize(); i++) {
439454
if (elements.getType(i) == ElementType.NON_UNIFORM) {
440455
if (returnNullIfInvalid) {
@@ -444,7 +459,7 @@ static ConfigurationPropertyName of(CharSequence name, boolean returnNullIfInval
444459
getInvalidChars(elements, i));
445460
}
446461
}
447-
return new ConfigurationPropertyName(elements);
462+
return elements;
448463
}
449464

450465
private static List<Character> getInvalidChars(Elements elements, int index) {
@@ -789,7 +804,7 @@ private void add(int start, int end, ElementType type,
789804
if ((end - start) < 1 || type == ElementType.EMPTY) {
790805
return;
791806
}
792-
if (this.start.length <= end) {
807+
if (this.start.length == this.size) {
793808
this.start = expand(this.start);
794809
this.end = expand(this.end);
795810
this.type = expand(this.type);

0 commit comments

Comments
 (0)