Skip to content

Provide optimized code path in check_regex_match function for non-regex strings#1466

Open
mgduda wants to merge 2 commits into
MPAS-Dev:developfrom
mgduda:framework/optimize_regex_match
Open

Provide optimized code path in check_regex_match function for non-regex strings#1466
mgduda wants to merge 2 commits into
MPAS-Dev:developfrom
mgduda:framework/optimize_regex_match

Conversation

@mgduda

@mgduda mgduda commented Jun 5, 2026

Copy link
Copy Markdown
Contributor

This PR provides an optimized code path in the check_regex_match function for non-regex strings. When the pattern argument to the check_regex_match function in regex_matching.c is not a regular expression, a simple string comparison is sufficient and the cost of compiling a regular expression can be avoided.

Thanks to Yu-Tze Hong and Ying-Jhang Wu for identifying this opportunity for optimization and for providing the initial code changes.

…ex strings

When the 'pattern' argument to the check_regex_match function in
regex_matching.c is not a regular expression, a simple string comparison is
sufficient and the cost of compiling a regular expression can be avoided. This
commit adds an optimized code path in the check_regex_match function for this
case.
@mgduda

mgduda commented Jun 5, 2026

Copy link
Copy Markdown
Contributor Author

The changes in this PR offer an alternative to those in PR #1456.

@jim-p-w jim-p-w left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me.

}


void check_regex_match(const char * pattern, const char * str, int *imatch)

@islas islas Jun 8, 2026

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it may be worth adding some function description to check_regex_match() especially as the internal helper function has details on the return value that differ slightly from the return values of imatch from the primary function in this file.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've just added documentation for the check_regex_match function with commit 384dff9.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants