HBASE-9428 Regex filters are at least an order of magnitude slower since 0.94.3

git-svn-id: https://svn.apache.org/repos/asf/hbase/trunk@1520095 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
larsh 2013-09-04 18:35:34 +00:00
parent 81b756f09b
commit b99bbd73b3
1 changed files with 5 additions and 2 deletions

View File

@ -30,6 +30,7 @@ import org.apache.hadoop.hbase.util.Bytes;
import java.nio.charset.Charset;
import java.nio.charset.IllegalCharsetNameException;
import java.util.Arrays;
import java.util.regex.Pattern;
/**
@ -108,10 +109,12 @@ public class RegexStringComparator extends ByteArrayComparable {
@Override
public int compareTo(byte[] value, int offset, int length) {
// See HBASE-9428. Make a copy of the relevant part of the byte[],
// or the JDK will copy the entire byte[] during String decode
byte[] tmp = Arrays.copyOfRange(value, offset, offset+length);
// Use find() for subsequence match instead of matches() (full sequence
// match) to adhere to the principle of least surprise.
return pattern.matcher(new String(value, offset, length, charset)).find() ? 0
: 1;
return pattern.matcher(new String(tmp, charset)).find() ? 0 : 1;
}
/**