Use split limit

This commit is contained in:
ebraminio
2014-10-06 11:37:37 +03:30
parent 56bcc5ef5e
commit 539d9c6d0e

View File

@@ -30,7 +30,7 @@ class EstimateDirection {
static boolean isRTL(String str) {
int rtlCount = 0;
int total = 0;
String[] tokens = WORD_SEPARATOR_RE.split(str);
String[] tokens = WORD_SEPARATOR_RE.split(str, 20); // limit splits to 20, usually enough
for (int i = 0; i < tokens.length; i++) {
String token = tokens[i];
if (startsWithRtl(token)) {
@@ -41,11 +41,6 @@ class EstimateDirection {
} else if (hasAnyLtr(token)) {
total++;
}
// only checking 20 first words is usually enough
if (i == 20) {
break;
}
}
return total == 0 ? false : ((float) rtlCount / total > RTL_DETECTION_THRESHOLD ? true : false);