From ea0fe6d64b36900757cf3cdc420a9e9015a656bc Mon Sep 17 00:00:00 2001 From: vrana Date: Tue, 14 Aug 2012 15:03:02 -0700 Subject: [PATCH] Optimize matching regexps in Herald rules Summary: We spend 6.37 s in this condition on a big diff. By adding the 'S' flag, the time is down to 2.15 s. Test Plan: `DifferentialRevisionEditor::newRevisionFromConduitWithDiff()` Reviewers: epriestley Reviewed By: epriestley CC: aran, Korvin Differential Revision: https://secure.phabricator.com/D3284 --- src/applications/herald/engine/HeraldEngine.php | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/applications/herald/engine/HeraldEngine.php b/src/applications/herald/engine/HeraldEngine.php index c7af631b7f..6fc64f5cf8 100644 --- a/src/applications/herald/engine/HeraldEngine.php +++ b/src/applications/herald/engine/HeraldEngine.php @@ -350,7 +350,10 @@ final class HeraldEngine { break; case HeraldConditionConfig::CONDITION_REGEXP: foreach ((array)$object_value as $value) { - $result = @preg_match($test_value, $value); + // We add the 'S' flag because we use the regexp multiple times. + // It shouldn't cause any troubles if the flag is already there + // - /.*/S is evaluated same as /.*/SS. + $result = @preg_match($test_value . 'S', $value); if ($result === false) { $transcript->setNote( "Regular expression is not valid!");