Skip to content

Commit 233f507

Browse files
committed
#1764 - Performance tweaks in TemplateVariable.toString(…).
Heavily inspired by the PR @MikeRocke, we removed all usage of String.format(…) from hot code paths triggered by ….toString() as it's used in general output a lot. Before: Benchmark Mode Cnt Score Error Units TemplateVariableBenchmark.toString(…) thrpt 3 2803239,270 ± 110258,955 ops/s After: Benchmark Mode Cnt Score Error Units TemplateVariableBenchmark.toString(…) thrpt 3 10753653,459 ± 156684,459 ops/s
1 parent 5f701b4 commit 233f507

File tree

1 file changed

+8
-5
lines changed

1 file changed

+8
-5
lines changed

src/main/java/org/springframework/hateoas/TemplateVariable.java

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -280,18 +280,21 @@ TemplateVariable withType(VariableType type) {
280280
*/
281281
@Override
282282
public String toString() {
283-
return StringUtils.hasText(description) ? String.format("%s - %s", asString(), description) : asString();
283+
return StringUtils.hasText(description) ? asString() + " - " + description : asString();
284284
}
285285

286286
public String asString() {
287-
return String.format("{%s%s}", type.toString(), essence());
287+
288+
return "{" + type.toString() + essence() + "}";
288289
}
289290

290291
String essence() {
291292

292-
return String.format("%s%s%s", name,
293-
limit != -1 ? ":".concat(String.valueOf(limit)) : "",
294-
isComposite() ? "*" : "");
293+
String result = name;
294+
result += limit != -1 ? ":" + limit : "";
295+
result += isComposite() ? "*" : "";
296+
297+
return result;
295298
}
296299

297300
public String getName() {

0 commit comments

Comments
 (0)