From c2df516faccd6d015e374825b5fbc423a7b3fda9 Mon Sep 17 00:00:00 2001 From: Tyson Andre Date: Thu, 26 Mar 2020 22:13:18 -0400 Subject: [PATCH] Improve performance when checking long words for typos Fix backtracking in this regex that harmed performance when there were long strings of lowercase letters without uppercase or underscores. --- src/TypoCheckUtils.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/TypoCheckUtils.php b/src/TypoCheckUtils.php index 3211b78..b46fbd2 100644 --- a/src/TypoCheckUtils.php +++ b/src/TypoCheckUtils.php @@ -108,7 +108,7 @@ public static function getTyposForText(string $contents, bool $plaintext = false $suggestions = $dictionary[strtolower($word)] ?? null; if ($suggestions === null) { // Analyze anything resembling camelCase, CamelCase, or snake_case - if (preg_match('/(?:[a-z].*[A-Z]|_)/', $word)) { + if (preg_match('/(?:[a-z][A-Z]|_)/', $word)) { preg_match_all('/[a-z]+|[A-Z](?:[a-z]+|[A-Z]+(?![a-z]))/', $word, $matches); if (count($matches[0]) >= 2) { foreach ($matches[0] as $inner_word) {