From a670613f0cd96261a3827e50c202dfd714dba264 Mon Sep 17 00:00:00 2001 From: Doug MacEachern Date: Thu, 28 Apr 2005 16:58:38 +0000 Subject: [PATCH] minor optmization for 0 or 1 match --- .../src/net/hyperic/sigar/ptql/ProcessFinder.java | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/bindings/java/src/net/hyperic/sigar/ptql/ProcessFinder.java b/bindings/java/src/net/hyperic/sigar/ptql/ProcessFinder.java index c5214b2f..e3e15071 100644 --- a/bindings/java/src/net/hyperic/sigar/ptql/ProcessFinder.java +++ b/bindings/java/src/net/hyperic/sigar/ptql/ProcessFinder.java @@ -9,6 +9,8 @@ import net.hyperic.sigar.SigarProxyCache; public class ProcessFinder { 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) { this.proxy = proxy; @@ -126,17 +128,19 @@ public class ProcessFinder { } else { pids[i] = -1; - continue; } } - long[] matched = new long[matches]; - if (matches == 1) { /* avoid loop below */ - matched[0] = pids[lastMatch]; - return matched; + ONE_MATCH[0] = pids[lastMatch]; + return ONE_MATCH; } + else if (matches == 0) { + return NO_MATCHES; + } + + long[] matched = new long[matches]; //XXX this is clunky for (int i=0, j=0; i<=lastMatch; i++) {