use List for fieldNames to reduce extra array construction

This commit is contained in:
kimchy 2010-06-14 04:36:03 +03:00
parent 953779ccea
commit c087bbe804
3 changed files with 9 additions and 9 deletions

View File

@ -168,7 +168,7 @@ public class FetchPhase implements SearchPhase {
return new UidAndSourceFieldSelector(); return new UidAndSourceFieldSelector();
} }
if (context.fieldNames().length == 0) { if (context.fieldNames().isEmpty()) {
return new UidFieldSelector(); return new UidFieldSelector();
} }

View File

@ -21,7 +21,7 @@ package org.elasticsearch.search.fetch;
import org.elasticsearch.search.SearchParseElement; import org.elasticsearch.search.SearchParseElement;
import org.elasticsearch.search.internal.SearchContext; import org.elasticsearch.search.internal.SearchContext;
import org.elasticsearch.util.Strings; import org.elasticsearch.util.collect.ImmutableList;
import org.elasticsearch.util.xcontent.XContentParser; import org.elasticsearch.util.xcontent.XContentParser;
import java.util.ArrayList; import java.util.ArrayList;
@ -39,12 +39,12 @@ public class FieldsParseElement implements SearchParseElement {
fieldNames.add(parser.text()); fieldNames.add(parser.text());
} }
if (fieldNames.isEmpty()) { if (fieldNames.isEmpty()) {
context.fieldNames(Strings.EMPTY_ARRAY); context.fieldNames(ImmutableList.<String>of());
} else { } else {
context.fieldNames(fieldNames.toArray(new String[fieldNames.size()])); context.fieldNames(fieldNames);
} }
} else if (token == XContentParser.Token.VALUE_STRING) { } else if (token == XContentParser.Token.VALUE_STRING) {
context.fieldNames(new String[]{parser.text()}); context.fieldNames(ImmutableList.of(parser.text()));
} }
} }
} }

View File

@ -44,6 +44,7 @@ import org.elasticsearch.util.lease.Releasable;
import org.elasticsearch.util.timer.Timeout; import org.elasticsearch.util.timer.Timeout;
import java.io.IOException; import java.io.IOException;
import java.util.List;
/** /**
* @author kimchy (shay.banon) * @author kimchy (shay.banon)
@ -75,7 +76,7 @@ public class SearchContext implements Releasable {
private boolean explain; private boolean explain;
private String[] fieldNames; private List<String> fieldNames;
private int from = -1; private int from = -1;
@ -101,7 +102,6 @@ public class SearchContext implements Releasable {
private SearchContextHighlight highlight; private SearchContextHighlight highlight;
private boolean queryRewritten; private boolean queryRewritten;
private volatile TimeValue keepAlive; private volatile TimeValue keepAlive;
@ -299,11 +299,11 @@ public class SearchContext implements Releasable {
return this; return this;
} }
public String[] fieldNames() { public List<String> fieldNames() {
return fieldNames; return fieldNames;
} }
public SearchContext fieldNames(String[] fieldNames) { public SearchContext fieldNames(List<String> fieldNames) {
this.fieldNames = fieldNames; this.fieldNames = fieldNames;
return this; return this;
} }