Skip to content
Browse files

optimized string starts with checks

Doing this with strpos() is slightly faster than substr().
  • Loading branch information...
1 parent c2c765d commit dec12c2e2d34b508c34c54fdb0b3ebe446d0c20a @kriswallsmith kriswallsmith committed
Showing with 3 additions and 3 deletions.
  1. +3 −3 Parser.php
View
6 Parser.php
@@ -114,7 +114,7 @@ public function parse($value)
}
if ('<<' === $key) {
- if (isset($values['value']) && '*' === substr($values['value'], 0, 1)) {
+ if (isset($values['value']) && 0 === strpos($values['value'], '*')) {
$isInPlace = substr($values['value'], 1);
if (!array_key_exists($isInPlace, $this->refs)) {
throw new ParseException(sprintf('Reference "%s" does not exist.', $isInPlace), $this->getRealCurrentLineNb() + 1, $this->currentLine);
@@ -188,7 +188,7 @@ public function parse($value)
if (is_array($value)) {
$first = reset($value);
- if (is_string($first) && '*' === substr($first, 0, 1)) {
+ if (is_string($first) && 0 === strpos($first, '*')) {
$data = array();
foreach ($value as $alias) {
$data[] = $this->refs[substr($alias, 1)];
@@ -347,7 +347,7 @@ private function moveToPreviousLine()
*/
private function parseValue($value)
{
- if ('*' === substr($value, 0, 1)) {
+ if (0 === strpos($value, '*')) {
if (false !== $pos = strpos($value, '#')) {
$value = substr($value, 1, $pos - 2);
} else {

0 comments on commit dec12c2

Please sign in to comment.
Something went wrong with that request. Please try again.