SOLR-971 -- Replace StringBuffer with StringBuilder for instances that do not require thread-safety

git-svn-id: https://svn.apache.org/repos/asf/lucene/solr/trunk@741262 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Shalin Shekhar Mangar 2009-02-05 19:41:55 +00:00
parent 23ab5e1869
commit 6f00fa6f7d
15 changed files with 30 additions and 16 deletions

View File

@ -168,6 +168,9 @@ Optimizations
with reusable priority queue entries to reduce the amount of
generated garbage during searching. (Mark Miller via yonik)
6. SOLR-971: Replace StringBuffer with StringBuilder for instances that do not require thread-safety.
(Kay Kay via shalin)
Bug Fixes
----------------------
1. SOLR-774: Fixed logging level display (Sean Timm via Otis Gospodnetic)

View File

@ -163,7 +163,7 @@ public class DataConfig {
public Script(Element e) {
this.language = getStringAttribute(e, "language", "JavaScript");
StringBuffer buffer = new StringBuffer();
StringBuilder buffer = new StringBuilder();
String script = getTxt(e, buffer);
if (script != null)
this.script = script.trim();
@ -268,8 +268,7 @@ public class DataConfig {
return m;
}
public static String getTxt(Node elem, StringBuffer buffer) {
public static String getTxt(Node elem, StringBuilder buffer) {
if (elem.getNodeType() != Node.CDATA_SECTION_NODE) {
NodeList childs = elem.getChildNodes();
for (int i = 0; i < childs.getLength(); i++) {

View File

@ -136,7 +136,7 @@ public class DataImporter {
}
if (!errors.isEmpty()) {
StringBuffer sb = new StringBuffer("There are errors in the Schema\n");
StringBuilder sb = new StringBuilder("There are errors in the Schema\n");
for (String error : errors) {
sb.append(error).append("\n");
}

View File

@ -129,7 +129,7 @@ public class SqlEntityProcessor extends EntityProcessorBase {
if(deltaImportQuery != null){
return resolver.replaceTokens(deltaImportQuery);
}
StringBuffer sb = new StringBuffer(queryString);
StringBuilder sb = new StringBuilder(queryString);
if (SELECT_WHERE_PATTERN.matcher(queryString).find()) {
sb.append(" and ");
} else {

View File

@ -86,7 +86,7 @@ public class TemplateString {
s[i] = val == null ? "" : getObjectAsString(val);
}
StringBuffer sb = new StringBuffer();
StringBuilder sb = new StringBuilder();
for (int i = 0; i < pcs.size(); i++) {
sb.append(pcs.get(i));
if (i < s.length) {

View File

@ -107,7 +107,7 @@ public class VariableResolverImpl extends VariableResolver {
private String mergeAll(String[] parts, int i) {
if (i == parts.length - 1)
return parts[parts.length - 1];
StringBuffer sb = new StringBuffer();
StringBuilder sb = new StringBuilder();
for (int j = i; j < parts.length; j++) {
sb.append(parts[j]);
if (j < parts.length - 1)

View File

@ -235,7 +235,7 @@ public class ReutersService {
* @throws java.io.IOException
*/
private static String readFileAsString(File file) throws java.io.IOException {
StringBuffer fileData = new StringBuffer(1000);
StringBuilder fileData = new StringBuilder(1000);
BufferedReader reader = new BufferedReader(new FileReader(file));
char[] buf = new char[1024];
int numRead=0;

View File

@ -287,7 +287,7 @@ public class DOMUtil {
List<String> propertyRefs = new ArrayList<String>();
parsePropertyString(value, fragments, propertyRefs);
StringBuffer sb = new StringBuffer();
StringBuilder sb = new StringBuilder();
Iterator<String> i = fragments.iterator();
Iterator<String> j = propertyRefs.iterator();

View File

@ -198,7 +198,7 @@ public class NamedList<T> implements Cloneable, Serializable, Iterable<Map.Entry
}
public String toString() {
StringBuffer sb = new StringBuffer();
StringBuilder sb = new StringBuilder();
sb.append('{');
int sz = size();
for (int i=0; i<sz; i++) {

View File

@ -63,7 +63,7 @@ public abstract class BaseCharFilter extends CharFilter {
}
public String toString(){
StringBuffer sb = new StringBuffer();
StringBuilder sb = new StringBuilder();
sb.append('(');
sb.append(pos);
sb.append(',');

View File

@ -49,7 +49,7 @@ public class ConstantScorePrefixQuery extends Query {
/** Prints a user-readable version of this query. */
public String toString(String field)
{
StringBuffer buffer = new StringBuffer();
StringBuilder buffer = new StringBuilder();
if (!prefix.field().equals(field)) {
buffer.append(prefix.field());
buffer.append(":");

View File

@ -263,7 +263,7 @@ public class TestHarness {
public String validateAddDoc(String... fieldsAndValues)
throws XPathExpressionException, SAXException, IOException {
StringBuffer buf = new StringBuffer();
StringBuilder buf = new StringBuilder();
buf.append("<add>");
appendSimpleDoc(buf, fieldsAndValues);
buf.append("</add>");
@ -389,10 +389,22 @@ public class TestHarness {
}
}
/**
* A helper that adds an xml &lt;doc&gt; containing all of the
* fields and values specified (odds are fields, evens are values)
* to a StringBuilder
*/
public void appendSimpleDoc(StringBuilder buf, String... fieldsAndValues)
throws IOException {
buf.append(makeSimpleDoc(fieldsAndValues));
}
/**
* A helper that adds an xml &lt;doc&gt; containing all of the
* fields and values specified (odds are fields, evens are values)
* to a StringBuffer.
* @deprecated see {@link #appendSimpleDoc(StringBuilder, String...)}
*/
public void appendSimpleDoc(StringBuffer buf, String... fieldsAndValues)
throws IOException {

View File

@ -176,7 +176,7 @@ public class ClientUtils
* See: http://lucene.apache.org/java/docs/queryparsersyntax.html#Escaping Special Characters
*/
public static String escapeQueryChars(String s) {
StringBuffer sb = new StringBuffer();
StringBuilder sb = new StringBuilder();
for (int i = 0; i < s.length(); i++) {
char c = s.charAt(i);
// These characters are part of the query syntax and must be escaped

View File

@ -34,7 +34,7 @@ import junit.framework.TestCase;
public abstract class BaseTokenTestCase extends AnalysisTestCase
{
public static String tsToString(TokenStream in) throws IOException {
StringBuffer out = new StringBuffer();
StringBuilder out = new StringBuilder();
Token t = in.next();
if (null != t)
out.append(new String(t.termBuffer(), 0, t.termLength()));

View File

@ -96,7 +96,7 @@ public class IteratorChainTest extends TestCase {
/** dump the contents of it to a String */
private String getString(Iterator<String> it) {
final StringBuffer sb = new StringBuffer();
final StringBuilder sb = new StringBuilder();
sb.append("");
while(it.hasNext()) {
sb.append(it.next());