Skip to content

Commit d9a360d

Browse files
mdeinumfmbenhassine
authored andcommitted
Better sizes for StringBuilder
StringBuilder by default has a size of 16, however there are some places that already create larger strings already. For efficiency and garbage reduction it would be better to have larger sizes to begin with.
1 parent 737f6ac commit d9a360d

File tree

4 files changed

+8
-8
lines changed

4 files changed

+8
-8
lines changed

spring-batch-infrastructure/src/main/java/org/springframework/batch/item/data/AbstractNeo4jItemReader.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2020 the original author or authors.
2+
* Copyright 2012-2021 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.
@@ -172,7 +172,7 @@ protected final Class<T> getTargetType() {
172172
}
173173

174174
protected String generateLimitCypherQuery() {
175-
StringBuilder query = new StringBuilder();
175+
StringBuilder query = new StringBuilder(128);
176176

177177
query.append("START ").append(startStatement);
178178
query.append(matchStatement != null ? " MATCH " + matchStatement : "");

spring-batch-infrastructure/src/main/java/org/springframework/batch/item/database/support/AbstractSqlPagingQueryProvider.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2006-2020 the original author or authors.
2+
* Copyright 2006-2021 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.
@@ -190,7 +190,7 @@ public void init(DataSource dataSource) throws Exception {
190190
Assert.hasLength(selectClause, "selectClause must be specified");
191191
Assert.hasLength(fromClause, "fromClause must be specified");
192192
Assert.notEmpty(sortKeys, "sortKey must be specified");
193-
StringBuilder sql = new StringBuilder();
193+
StringBuilder sql = new StringBuilder(64);
194194
sql.append("SELECT ").append(selectClause);
195195
sql.append(" FROM ").append(fromClause);
196196
if (whereClause != null) {

spring-batch-infrastructure/src/main/java/org/springframework/batch/item/database/support/SqlPagingQueryUtils.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2006-2015 the original author or authors.
2+
* Copyright 2006-2021 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.
@@ -98,7 +98,7 @@ public static String generateLimitGroupedSqlQuery(AbstractSqlPagingQueryProvider
9898
*/
9999
public static String generateTopSqlQuery(AbstractSqlPagingQueryProvider provider, boolean remainingPageQuery,
100100
String topClause) {
101-
StringBuilder sql = new StringBuilder();
101+
StringBuilder sql = new StringBuilder(128);
102102
sql.append("SELECT ").append(topClause).append(" ").append(provider.getSelectClause());
103103
sql.append(" FROM ").append(provider.getFromClause());
104104
buildWhereClause(provider, remainingPageQuery, sql);

spring-batch-infrastructure/src/main/java/org/springframework/batch/item/file/mapping/PropertyMatches.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2006-2007 the original author or authors.
2+
* Copyright 2006-2021 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.
@@ -99,7 +99,7 @@ public String[] getPossibleMatches() {
9999
* indicating the possible property matches.
100100
*/
101101
public String buildErrorMessage() {
102-
StringBuilder buf = new StringBuilder();
102+
StringBuilder buf = new StringBuilder(128);
103103
buf.append("Bean property '");
104104
buf.append(this.propertyName);
105105
buf.append("' is not writable or has an invalid setter method. ");

0 commit comments

Comments
 (0)