Skip to content

Commit e241565

Browse files
committed
RequestFactory: optimized script path detection performance
1 parent e9dd988 commit e241565

File tree

1 file changed

+8
-6
lines changed

1 file changed

+8
-6
lines changed

src/Http/RequestFactory.php

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -113,16 +113,18 @@ public function createHttpRequest()
113113
$script = '/';
114114
}
115115

116-
$path = strtolower($url->getPath()) . '/';
117-
$script = strtolower($script) . '/';
118-
$max = min(strlen($path), strlen($script));
119-
for ($i = 0; $i < $max; $i++) {
120-
if ($path[$i] !== $script[$i]) {
116+
$path = $url->getPath();
117+
$max = min(strlen($path), strlen($script)) - 1;
118+
for ($i = 0, $j = 0; $i <= $max; $i++) {
119+
if ($path[$i] !== $script[$i] && strcasecmp($path[$i], $script[$i])) {
121120
break;
122121
} elseif ($path[$i] === '/') {
123-
$url->setScriptPath(substr($url->getPath(), 0, $i + 1));
122+
$j = $i;
123+
} elseif ($i === $max) {
124+
$j = $i + 1;
124125
}
125126
}
127+
$url->setScriptPath(substr($path, 0, $j + 1));
126128

127129
// GET, POST, COOKIE
128130
$useFilter = (!in_array(ini_get('filter.default'), array('', 'unsafe_raw')) || ini_get('filter.default_flags'));

0 commit comments

Comments
 (0)