hsluoyz commented on PR #279: URL: https://github.com/apache/casbin-cpp/pull/279#issuecomment-6537625261
Thanks @cbaecker, the fast path idea is good and the numbers made the case. I've pushed a reworked version directly to master in https://github.com/apache/casbin-cpp/commit/2e99457, so I'm closing this PR in favor of it: - The fast path is a single `find_first_of` over the regex special characters (plus `:` for `keyMatch2`). With no special character it's plain equality; with only a trailing `/*` it's a prefix check. Everything else still goes to the regex. - The trailing `/*` case also checks that the rest of `key1` has no `\r` or `\n`, because `.` in `/.*` doesn't match line terminators. This keeps it exactly equivalent to the regex. - `keyMatch4` uses the same fast path, and `keyMatch5` gets it through `keyMatch3`. - Compiled regexes are cached per thread (`thread_local`, capped at 1024 patterns), so patterns with placeholders and `regexMatch` no longer recompile on every call either. I checked it against the old regex-only `keyMatch2`/`keyMatch3` on ~520k random key/pattern pairs with no differences, and added a few test cases. On a small policy set of plain, `/*` and `:id` paths it's about 10x faster. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected] --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
