minor optmization for 0 or 1 match

This commit is contained in:
Doug MacEachern 2005-04-28 16:58:38 +00:00
parent 41a75d9253
commit a670613f0c
1 changed files with 9 additions and 5 deletions

View File

@ -9,6 +9,8 @@ import net.hyperic.sigar.SigarProxyCache;
public class ProcessFinder { public class ProcessFinder {
private SigarProxy proxy; private SigarProxy proxy;
private static final long[] NO_MATCHES = new long[0];
private static final long[] ONE_MATCH = new long[1];
public ProcessFinder(SigarProxy proxy) { public ProcessFinder(SigarProxy proxy) {
this.proxy = proxy; this.proxy = proxy;
@ -126,17 +128,19 @@ public class ProcessFinder {
} }
else { else {
pids[i] = -1; pids[i] = -1;
continue;
} }
} }
long[] matched = new long[matches];
if (matches == 1) { if (matches == 1) {
/* avoid loop below */ /* avoid loop below */
matched[0] = pids[lastMatch]; ONE_MATCH[0] = pids[lastMatch];
return matched; return ONE_MATCH;
} }
else if (matches == 0) {
return NO_MATCHES;
}
long[] matched = new long[matches];
//XXX this is clunky //XXX this is clunky
for (int i=0, j=0; i<=lastMatch; i++) { for (int i=0, j=0; i<=lastMatch; i++) {