From ef7876e517d6198b66d974f9365689c67e5367e8 Mon Sep 17 00:00:00 2001 From: Christian Flothmann Date: Sun, 27 Jan 2019 11:32:59 +0100 Subject: [PATCH] speed up accessing object properties --- .../PropertyAccess/PropertyAccessor.php | 25 +++++++++++++++++-- 1 file changed, 23 insertions(+), 2 deletions(-) diff --git a/src/Symfony/Component/PropertyAccess/PropertyAccessor.php b/src/Symfony/Component/PropertyAccess/PropertyAccessor.php index f063e8f007438..aae083e4b7f0d 100644 --- a/src/Symfony/Component/PropertyAccess/PropertyAccessor.php +++ b/src/Symfony/Component/PropertyAccess/PropertyAccessor.php @@ -82,11 +82,16 @@ public function __construct(bool $magicCall = false, bool $throwExceptionOnInval */ public function getValue($objectOrArray, $propertyPath) { - $propertyPath = $this->getPropertyPath($propertyPath); - $zval = [ self::VALUE => $objectOrArray, ]; + + if (\is_object($objectOrArray) && false === strpbrk((string) $propertyPath, '.[')) { + return $this->readProperty($zval, $propertyPath)[self::VALUE]; + } + + $propertyPath = $this->getPropertyPath($propertyPath); + $propertyValues = $this->readPropertiesUntil($zval, $propertyPath, $propertyPath->getLength(), $this->ignoreInvalidIndices); return $propertyValues[\count($propertyValues) - 1][self::VALUE]; @@ -97,6 +102,22 @@ public function getValue($objectOrArray, $propertyPath) */ public function setValue(&$objectOrArray, $propertyPath, $value) { + if (\is_object($objectOrArray) && false === strpbrk((string) $propertyPath, '.[')) { + $zval = [ + self::VALUE => $objectOrArray, + ]; + + try { + $this->writeProperty($zval, $propertyPath, $value); + + return; + } catch (\TypeError $e) { + self::throwInvalidArgumentException($e->getMessage(), $e->getTrace(), 0, $propertyPath); + // It wasn't thrown in this class so rethrow it + throw $e; + } + } + $propertyPath = $this->getPropertyPath($propertyPath); $zval = [ pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy