Skip to content

Commit 197e4cc

Browse files
committed
Polishing.
Use for-loop instead of Java Stream API for concatenation of paths to reduce GC and CPU pressure. See #2992
1 parent ee452d5 commit 197e4cc

File tree

1 file changed

+21
-6
lines changed

1 file changed

+21
-6
lines changed

src/main/java/org/springframework/data/mapping/context/DefaultPersistentPropertyPath.java

+21-6
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919
import java.util.Collections;
2020
import java.util.Iterator;
2121
import java.util.List;
22-
import java.util.stream.Collectors;
2322

2423
import org.springframework.core.convert.converter.Converter;
2524
import org.springframework.data.mapping.PersistentProperty;
@@ -28,7 +27,6 @@
2827
import org.springframework.lang.Nullable;
2928
import org.springframework.util.Assert;
3029
import org.springframework.util.ObjectUtils;
31-
import org.springframework.util.StringUtils;
3230

3331
/**
3432
* Abstraction of a path of {@link PersistentProperty}s.
@@ -111,10 +109,27 @@ public String toPath(String delimiter, Converter<? super P, String> converter) {
111109
Assert.hasText(delimiter, "Delimiter must not be null or empty");
112110
Assert.notNull(converter, "Converter must not be null");
113111

114-
return properties.stream() //
115-
.map(converter::convert) //
116-
.filter(StringUtils::hasText) //
117-
.collect(Collectors.joining(delimiter));
112+
StringBuilder builder = null;
113+
for (P property : properties) {
114+
115+
String converted = converter.convert(property);
116+
117+
if (ObjectUtils.isEmpty(converted)) {
118+
continue;
119+
}
120+
121+
if (builder == null) {
122+
builder = new StringBuilder();
123+
}
124+
125+
if (!builder.isEmpty()) {
126+
builder.append(delimiter);
127+
}
128+
129+
builder.append(converted);
130+
}
131+
132+
return builder == null ? "" : builder.toString();
118133
}
119134

120135
@Override

0 commit comments

Comments
 (0)