Prefer ArrayList/ArrayDeque over LinkedList for multi-element holders

LinkedList remains in place where a List is likely to remain empty or single-element (in order to avoid unused capacity).

Issue: SPR-17037

(cherry picked from commit 9c08a48)
This commit is contained in:
Juergen Hoeller
2018-07-18 22:17:42 +02:00
parent ed54895e53
commit 11fc086309
27 changed files with 119 additions and 125 deletions
@@ -22,7 +22,7 @@ import java.sql.Connection;
import java.sql.SQLException;
import java.sql.SQLWarning;
import java.sql.Statement;
import java.util.LinkedList;
import java.util.ArrayList;
import java.util.List;
import org.apache.commons.logging.Log;
@@ -339,7 +339,7 @@ public abstract class ScriptUtils {
/**
* Does the provided SQL script contain the specified delimiter?
* @param script the SQL script
* @param delim String delimiting each statement - typically a ';' character
* @param delim the string delimiting each statement - typically a ';' character
*/
public static boolean containsSqlScriptDelimiters(String script, String delim) {
boolean inLiteral = false;
@@ -460,7 +460,7 @@ public abstract class ScriptUtils {
separator = FALLBACK_STATEMENT_SEPARATOR;
}
List<String> statements = new LinkedList<>();
List<String> statements = new ArrayList<>();
splitSqlScript(resource, script, separator, commentPrefix, blockCommentStartDelimiter,
blockCommentEndDelimiter, statements);
@@ -1,5 +1,5 @@
/*
* Copyright 2002-2016 the original author or authors.
* Copyright 2002-2018 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.
@@ -18,9 +18,10 @@ package org.springframework.jdbc.object;
import java.sql.PreparedStatement;
import java.sql.SQLException;
import java.util.ArrayDeque;
import java.util.ArrayList;
import java.util.Deque;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
import javax.sql.DataSource;
@@ -55,7 +56,7 @@ public class BatchSqlUpdate extends SqlUpdate {
private boolean trackRowsAffected = true;
private final LinkedList<Object[]> parameterQueue = new LinkedList<>();
private final Deque<Object[]> parameterQueue = new ArrayDeque<>();
private final List<Integer> rowsAffected = new ArrayList<>();
@@ -72,8 +73,8 @@ public class BatchSqlUpdate extends SqlUpdate {
/**
* Construct an update object with a given DataSource and SQL.
* @param ds DataSource to use to obtain connections
* @param sql SQL statement to execute
* @param ds the DataSource to use to obtain connections
* @param sql the SQL statement to execute
*/
public BatchSqlUpdate(DataSource ds, String sql) {
super(ds, sql);
@@ -82,9 +83,9 @@ public class BatchSqlUpdate extends SqlUpdate {
/**
* Construct an update object with a given DataSource, SQL
* and anonymous parameters.
* @param ds DataSource to use to obtain connections
* @param sql SQL statement to execute
* @param types SQL types of the parameters, as defined in the
* @param ds the DataSource to use to obtain connections
* @param sql the SQL statement to execute
* @param types the SQL types of the parameters, as defined in the
* {@code java.sql.Types} class
* @see java.sql.Types
*/
@@ -96,9 +97,9 @@ public class BatchSqlUpdate extends SqlUpdate {
* Construct an update object with a given DataSource, SQL,
* anonymous parameters and specifying the maximum number of rows
* that may be affected.
* @param ds DataSource to use to obtain connections
* @param sql SQL statement to execute
* @param types SQL types of the parameters, as defined in the
* @param ds the DataSource to use to obtain connections
* @param sql the SQL statement to execute
* @param types the SQL types of the parameters, as defined in the
* {@code java.sql.Types} class
* @param batchSize the number of statements that will trigger
* an automatic intermediate flush