From d68c4517118593c6f6b2deb8b6e926f87d18ee82 Mon Sep 17 00:00:00 2001 From: Nicolas Grekas Date: Fri, 13 Jan 2017 10:44:13 +0100 Subject: [PATCH] [Cache] Using strpbrk() instead of strcspn() is faster --- src/Symfony/Component/Cache/CacheItem.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Symfony/Component/Cache/CacheItem.php b/src/Symfony/Component/Cache/CacheItem.php index bdef410ca2675..d8ceb28ebdb74 100644 --- a/src/Symfony/Component/Cache/CacheItem.php +++ b/src/Symfony/Component/Cache/CacheItem.php @@ -101,7 +101,7 @@ public function expiresAfter($time) * * @param string $key The key to validate * - * @throws InvalidArgumentException When $key is not valid. + * @throws InvalidArgumentException When $key is not valid */ public static function validateKey($key) { @@ -111,7 +111,7 @@ public static function validateKey($key) if (!isset($key[0])) { throw new InvalidArgumentException('Cache key length must be greater than zero'); } - if (isset($key[strcspn($key, '{}()/\@:')])) { + if (false !== strpbrk($key, '{}()/\@:')) { throw new InvalidArgumentException(sprintf('Cache key "%s" contains reserved characters {}()/\@:', $key)); } }