mirror of
https://github.com/spring-projects/spring-framework.git
synced 2026-09-25 16:29:28 +00:00
Backported "Work around JDK7 String#substring performance regression"
Issue: SPR-9781 Issue: SPR-9784
This commit is contained in:
+24
-7
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2011 the original author or authors.
|
||||
* Copyright 2002-2012 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.
|
||||
@@ -43,13 +43,14 @@ import org.springframework.util.StringUtils;
|
||||
* @author Dave Syer
|
||||
* @author Juergen Hoeller
|
||||
* @author Chris Beams
|
||||
* @author Oliver Gierke
|
||||
* @since 3.0
|
||||
*/
|
||||
public class ResourceDatabasePopulator implements DatabasePopulator {
|
||||
|
||||
private static String DEFAULT_COMMENT_PREFIX = "--";
|
||||
private static final String DEFAULT_COMMENT_PREFIX = "--";
|
||||
|
||||
private static String DEFAULT_STATEMENT_SEPARATOR = ";";
|
||||
private static final String DEFAULT_STATEMENT_SEPARATOR = ";";
|
||||
|
||||
private static final Log logger = LogFactory.getLog(ResourceDatabasePopulator.class);
|
||||
|
||||
@@ -265,7 +266,7 @@ public class ResourceDatabasePopulator implements DatabasePopulator {
|
||||
if (content[i] == '\'') {
|
||||
inLiteral = !inLiteral;
|
||||
}
|
||||
if (!inLiteral && script.substring(i).startsWith(delim)) {
|
||||
if (!inLiteral && startsWithDelimiter(script, i, delim)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -273,8 +274,24 @@ public class ResourceDatabasePopulator implements DatabasePopulator {
|
||||
}
|
||||
|
||||
/**
|
||||
* Split an SQL script into separate statements delimited with the provided delimiter character.
|
||||
* Each individual statement will be added to the provided <code>List</code>.
|
||||
* Return whether the substring of a given source {@link String} starting at the
|
||||
* given index starts with the given delimiter.
|
||||
* @param source the source {@link String} to inspect
|
||||
* @param startIndex the index to look for the delimiter
|
||||
* @param delim the delimiter to look for
|
||||
*/
|
||||
private boolean startsWithDelimiter(String source, int startIndex, String delim) {
|
||||
int endIndex = startIndex + delim.length();
|
||||
if (source.length() < endIndex) {
|
||||
// String is too short to contain the delimiter
|
||||
return false;
|
||||
}
|
||||
return source.substring(startIndex, endIndex).equals(delim);
|
||||
}
|
||||
|
||||
/**
|
||||
* Split an SQL script into separate statements delimited with the provided delimiter
|
||||
* character. Each individual statement will be added to the provided {@code List}.
|
||||
* @param script the SQL script
|
||||
* @param delim character delimiting each statement (typically a ';' character)
|
||||
* @param statements the List that will contain the individual statements
|
||||
@@ -301,7 +318,7 @@ public class ResourceDatabasePopulator implements DatabasePopulator {
|
||||
inLiteral = !inLiteral;
|
||||
}
|
||||
if (!inLiteral) {
|
||||
if (script.substring(i).startsWith(delim)) {
|
||||
if (startsWithDelimiter(script, i, delim)) {
|
||||
if (sb.length() > 0) {
|
||||
statements.add(sb.toString());
|
||||
sb = new StringBuilder();
|
||||
|
||||
Reference in New Issue
Block a user