From 539d9c6d0e4b405954ee5109a0d5015dc5b23d38 Mon Sep 17 00:00:00 2001 From: ebraminio Date: Mon, 6 Oct 2014 11:37:37 +0330 Subject: [PATCH] Use split limit --- .../java/com/commafeed/backend/feed/EstimateDirection.java | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/src/main/java/com/commafeed/backend/feed/EstimateDirection.java b/src/main/java/com/commafeed/backend/feed/EstimateDirection.java index 504d544e..701f6068 100644 --- a/src/main/java/com/commafeed/backend/feed/EstimateDirection.java +++ b/src/main/java/com/commafeed/backend/feed/EstimateDirection.java @@ -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);