Skip to content

Commit d9b7232

Browse files
committed
Create large buffer only if needed
1 parent f045fcb commit d9b7232

File tree

1 file changed

+5
-5
lines changed
  • opengrok-indexer/src/main/java/org/opengrok/indexer/search/context

1 file changed

+5
-5
lines changed

opengrok-indexer/src/main/java/org/opengrok/indexer/search/context/Context.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,6 @@ public class Context {
6363
private final Query query;
6464
private final QueryBuilder qbuilder;
6565
private final LineMatcher[] m;
66-
private char[] buffer;
6766
PlainLineTokenizer tokens;
6867
String queryAsURI;
6968

@@ -99,7 +98,6 @@ public Context(Query query, QueryBuilder qbuilder) {
9998
if (m != null) {
10099
buildQueryAsURI(qbuilder.getQueries());
101100
//System.err.println("Found Matchers = "+ m.length + " for " + query);
102-
buffer = new char[MAXFILEREAD];
103101
tokens = new PlainLineTokenizer((Reader) null);
104102
}
105103
}
@@ -213,7 +211,7 @@ public boolean getContext2(RuntimeEnvironment env, IndexSearcher searcher,
213211

214212
try {
215213
List<String> fieldList = qbuilder.getContextFields();
216-
String[] fields = fieldList.toArray(new String[fieldList.size()]);
214+
String[] fields = fieldList.toArray(new String[0]);
217215

218216
String res = uhi.highlightFieldsUnion(fields, query, docId,
219217
linelimit);
@@ -299,7 +297,8 @@ public boolean getContext(Reader in, Writer out, String urlPrefix,
299297
if (scopes != null) {
300298
Scope scp = scopes.getScope(tag.line);
301299
scope = scp.getName() + "()";
302-
scopeUrl = "<a href=\"" + urlPrefixE + pathE + "#" + Integer.toString(scp.getLineFrom()) + "\">" + scope + "</a>";
300+
scopeUrl = "<a href=\"" + urlPrefixE + pathE + "#" +
301+
scp.getLineFrom() + "\">" + scope + "</a>";
303302
}
304303

305304
/* desc[0] is matched symbol
@@ -368,7 +367,7 @@ public boolean getContext(Reader in, Writer out, String urlPrefix,
368367
if (in == null) {
369368
return anything;
370369
}
371-
int charsRead = 0;
370+
int charsRead;
372371
boolean truncated = false;
373372

374373
boolean lim = limit;
@@ -378,6 +377,7 @@ public boolean getContext(Reader in, Writer out, String urlPrefix,
378377
}
379378

380379
if (lim) {
380+
char[] buffer = new char[MAXFILEREAD];
381381
try {
382382
charsRead = in.read(buffer);
383383
if (charsRead == MAXFILEREAD) {

0 commit comments

Comments
 (0)