From e9bdcc6d66fa7b3d91d0817501e3885e91e4e55e Mon Sep 17 00:00:00 2001 From: Marten Deinum Date: Thu, 3 Dec 2020 16:12:21 +0100 Subject: [PATCH] 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. --- .../batch/item/data/AbstractNeo4jItemReader.java | 4 ++-- .../item/database/support/AbstractSqlPagingQueryProvider.java | 4 ++-- .../batch/item/database/support/SqlPagingQueryUtils.java | 4 ++-- .../batch/item/file/mapping/PropertyMatches.java | 4 ++-- 4 files changed, 8 insertions(+), 8 deletions(-) diff --git a/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/data/AbstractNeo4jItemReader.java b/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/data/AbstractNeo4jItemReader.java index 7eb3dd82d..d244afc73 100644 --- a/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/data/AbstractNeo4jItemReader.java +++ b/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/data/AbstractNeo4jItemReader.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2020 the original author or authors. + * Copyright 2012-2021 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -172,7 +172,7 @@ public abstract class AbstractNeo4jItemReader extends } protected String generateLimitCypherQuery() { - StringBuilder query = new StringBuilder(); + StringBuilder query = new StringBuilder(128); query.append("START ").append(startStatement); query.append(matchStatement != null ? " MATCH " + matchStatement : ""); diff --git a/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/database/support/AbstractSqlPagingQueryProvider.java b/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/database/support/AbstractSqlPagingQueryProvider.java index e38619845..9f726a7a7 100644 --- a/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/database/support/AbstractSqlPagingQueryProvider.java +++ b/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/database/support/AbstractSqlPagingQueryProvider.java @@ -1,5 +1,5 @@ /* - * Copyright 2006-2020 the original author or authors. + * Copyright 2006-2021 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -190,7 +190,7 @@ public abstract class AbstractSqlPagingQueryProvider implements PagingQueryProvi Assert.hasLength(selectClause, "selectClause must be specified"); Assert.hasLength(fromClause, "fromClause must be specified"); Assert.notEmpty(sortKeys, "sortKey must be specified"); - StringBuilder sql = new StringBuilder(); + StringBuilder sql = new StringBuilder(64); sql.append("SELECT ").append(selectClause); sql.append(" FROM ").append(fromClause); if (whereClause != null) { diff --git a/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/database/support/SqlPagingQueryUtils.java b/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/database/support/SqlPagingQueryUtils.java index f3b9990cd..a180cdf7e 100644 --- a/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/database/support/SqlPagingQueryUtils.java +++ b/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/database/support/SqlPagingQueryUtils.java @@ -1,5 +1,5 @@ /* - * Copyright 2006-2015 the original author or authors. + * Copyright 2006-2021 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -98,7 +98,7 @@ public class SqlPagingQueryUtils { */ public static String generateTopSqlQuery(AbstractSqlPagingQueryProvider provider, boolean remainingPageQuery, String topClause) { - StringBuilder sql = new StringBuilder(); + StringBuilder sql = new StringBuilder(128); sql.append("SELECT ").append(topClause).append(" ").append(provider.getSelectClause()); sql.append(" FROM ").append(provider.getFromClause()); buildWhereClause(provider, remainingPageQuery, sql); diff --git a/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/file/mapping/PropertyMatches.java b/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/file/mapping/PropertyMatches.java index c47f70027..e39176e45 100644 --- a/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/file/mapping/PropertyMatches.java +++ b/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/file/mapping/PropertyMatches.java @@ -1,5 +1,5 @@ /* - * Copyright 2006-2007 the original author or authors. + * Copyright 2006-2021 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -99,7 +99,7 @@ final class PropertyMatches { * indicating the possible property matches. */ public String buildErrorMessage() { - StringBuilder buf = new StringBuilder(); + StringBuilder buf = new StringBuilder(128); buf.append("Bean property '"); buf.append(this.propertyName); buf.append("' is not writable or has an invalid setter method. ");