Change convertFromDiskFormat to use substring splitting vs using split operation (slow). patch by goffinet; reviewed by stuhood for CASSANDRA-581

git-svn-id: https://svn.apache.org/repos/asf/incubator/cassandra/trunk@887481 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Chris Goffinet 2009-12-05 01:44:41 +00:00
parent 55e13fe616
commit 75db7b59b7
1 changed files with 5 additions and 6 deletions

View File

@ -39,9 +39,6 @@ public class RandomPartitioner implements IPartitioner<BigIntegerToken>
private static final String DELIMITER = ":";
//to avoid having to create the pattern on every String.split
private Pattern diskDelimiter = Pattern.compile(DELIMITER);
private static final Comparator<DecoratedKey<BigIntegerToken>> comparator =
new Comparator<DecoratedKey<BigIntegerToken>>() {
public int compare(DecoratedKey<BigIntegerToken> o1, DecoratedKey<BigIntegerToken> o2)
@ -64,9 +61,11 @@ public class RandomPartitioner implements IPartitioner<BigIntegerToken>
public DecoratedKey<BigIntegerToken> convertFromDiskFormat(String key)
{
String[] parts = diskDelimiter.split(key, 2);
assert parts.length == 2;
return new DecoratedKey<BigIntegerToken>(new BigIntegerToken(parts[0]), parts[1]);
int splitPoint = key.indexOf(DELIMITER);
String first = key.substring(0, splitPoint);
String second = key.substring(splitPoint+1);
return new DecoratedKey<BigIntegerToken>(new BigIntegerToken(first), second);
}
public String convertToDiskFormat(DecoratedKey<BigIntegerToken> key)