Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Regular Expression Optimization for Phalcon\Mvc\Router #977

Merged
merged 7 commits into from Aug 2, 2013
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Regexps are shorter with possesive quantifiers
  • Loading branch information
sjinks committed Aug 2, 2013
commit e1ebbc65bf65c0a642bea16ea0a4fc5ab79b8110
4 changes: 2 additions & 2 deletions ext/mvc/router.c
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ PHP_METHOD(Phalcon_Mvc_Router, __construct){
add_assoc_long_ex(paths, SS("controller"), 1);

PHALCON_INIT_VAR(action_pattern);
ZVAL_STRING(action_pattern, "#^/((?>[a-zA-Z0-9_-]+))/?$#", 1);
ZVAL_STRING(action_pattern, "#^/([a-zA-Z0-9_-]++)/?+$#", 1);

PHALCON_INIT_VAR(route);
object_init_ex(route, phalcon_mvc_router_route_ce);
Expand All @@ -152,7 +152,7 @@ PHP_METHOD(Phalcon_Mvc_Router, __construct){
add_assoc_long_ex(paths, SS("params"), 3);

PHALCON_INIT_VAR(params_pattern);
ZVAL_STRING(params_pattern, "#^/((?>[a-zA-Z0-9_-]+))/((?>[a-zA-Z0-9\\._]+))((?>/.*))?$#", 1);
ZVAL_STRING(params_pattern, "#^/([a-zA-Z0-9_-]++)/([a-zA-Z0-9\\._]++)(/.*+)?+$#", 1);

PHALCON_INIT_NVAR(route);
object_init_ex(route, phalcon_mvc_router_route_ce);
Expand Down
6 changes: 3 additions & 3 deletions ext/mvc/router/route.c
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ PHP_METHOD(Phalcon_Mvc_Router_Route, compilePattern){
* This is a pattern for valid identifiers
*/
PHALCON_INIT_VAR(id_pattern);
ZVAL_STRING(id_pattern, "/((?>[a-zA-Z0-9_-]+))", 1);
ZVAL_STRING(id_pattern, "/([a-zA-Z0-9_-]++)", 1);

/**
* Replace the module part
Expand Down Expand Up @@ -209,7 +209,7 @@ PHP_METHOD(Phalcon_Mvc_Router_Route, compilePattern){
ZVAL_STRING(wildcard, "/:params", 1);

PHALCON_INIT_VAR(params_pattern);
ZVAL_STRING(params_pattern, "(?>(/.*))?", 1);
ZVAL_STRING(params_pattern, "(/.*+)?+", 1);
PHALCON_CPY_WRT(pattern_copy, compiled_pattern);

PHALCON_INIT_NVAR(compiled_pattern);
Expand All @@ -224,7 +224,7 @@ PHP_METHOD(Phalcon_Mvc_Router_Route, compilePattern){
ZVAL_STRING(wildcard, "/:int", 1);

PHALCON_INIT_VAR(int_pattern);
ZVAL_STRING(int_pattern, "/((?>[0-9]+))", 1);
ZVAL_STRING(int_pattern, "/([0-9]++)", 1);
PHALCON_CPY_WRT(pattern_copy, compiled_pattern);

PHALCON_INIT_NVAR(compiled_pattern);
Expand Down