From 131d2c2051f7bf9f54d6a9cb89da79cdd67fa3a6 Mon Sep 17 00:00:00 2001 From: Philippe Marschall Date: Sat, 31 Dec 2016 10:00:30 +0100 Subject: [PATCH] Remove String#toCharArray from ScriptUtils ScriptUtils contains two calls to String#toCharArray for the sole purpose to iterating over all chars in a String. Not only is this unnecessary and can be replaced with String#charAt it also causes additional allocator and heap pressure because String#toCharArray rather than returning the backing array (which is gone in Java 9) creates a copy. This commit contains the following changes: - remove String#toCharArray from ScriptUtils and replace with String#charAt Issue: SPR-15075 --- .../springframework/jdbc/datasource/init/ScriptUtils.java | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/spring-jdbc/src/main/java/org/springframework/jdbc/datasource/init/ScriptUtils.java b/spring-jdbc/src/main/java/org/springframework/jdbc/datasource/init/ScriptUtils.java index da4125421b..77d302eeff 100644 --- a/spring-jdbc/src/main/java/org/springframework/jdbc/datasource/init/ScriptUtils.java +++ b/spring-jdbc/src/main/java/org/springframework/jdbc/datasource/init/ScriptUtils.java @@ -178,9 +178,8 @@ public abstract class ScriptUtils { boolean inSingleQuote = false; boolean inDoubleQuote = false; boolean inEscape = false; - char[] content = script.toCharArray(); for (int i = 0; i < script.length(); i++) { - char c = content[i]; + char c = script.charAt(i); if (inEscape) { inEscape = false; sb.append(c); @@ -342,9 +341,8 @@ public abstract class ScriptUtils { */ public static boolean containsSqlScriptDelimiters(String script, String delim) { boolean inLiteral = false; - char[] content = script.toCharArray(); for (int i = 0; i < script.length(); i++) { - if (content[i] == '\'') { + if (script.charAt(i) == '\'') { inLiteral = !inLiteral; } if (!inLiteral && script.startsWith(delim, i)) {