HBASE-9711 Improve HBASE-9428 - avoid copying bytes for RegexFilter unless necessary

git-svn-id: https://svn.apache.org/repos/asf/hbase/trunk@1530059 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
larsh 2013-10-07 20:57:21 +00:00
parent 1fee106d6c
commit c28b58f280
1 changed files with 9 additions and 4 deletions

View File

@ -109,12 +109,17 @@ 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(tmp, charset)).find() ? 0 : 1;
String tmp;
if (length < value.length / 2) {
// See HBASE-9428. Make a copy of the relevant part of the byte[],
// or the JDK will copy the entire byte[] during String decode
tmp = new String(Arrays.copyOfRange(value, offset, offset + length), charset);
} else {
tmp = new String(value, offset, length, charset);
}
return pattern.matcher(tmp).find() ? 0 : 1;
}
/**