8000 feature #28277 [Serializer] AbstractObjectNormalizer improve performa… · symfony/symfony@53ffa66 · GitHub
[go: up one dir, main page]

Skip to content

Commit 53ffa66

Browse files
committed
feature #28277 [Serializer] AbstractObjectNormalizer improve performance (martiis)
This PR was merged into the 4.2-dev branch. Discussion ---------- [Serializer] AbstractObjectNormalizer improve performance | Q | A | ------------- | --- | Branch? | master | Bug fix? | no | New feature? | no | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | #28276 | License | MIT Check ticket for description Commits ------- 4224145 [Serializer] AbstractObjectNormalizer improve perf when checking types
2 parents 6cc2bd6 + 4224145 commit 53ffa66

File tree

1 file changed

+11
-3
lines changed

1 file changed

+11
-3
lines changed

src/Symfony/Component/Serializer/Normalizer/AbstractObjectNormalizer.php

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ abstract class AbstractObjectNormalizer extends AbstractNormalizer
3737
const DISABLE_TYPE_ENFORCEMENT = 'disable_type_enforcement';
3838

3939
private $propertyTypeExtractor;
40+
private $typesCache = array();
4041
private $attributesCache = array();
4142

4243
/**
@@ -366,24 +367,31 @@ private function getTypes(string $currentClass, string $attribute)
366367
return null;
367368
}
368369

370+
$key = $currentClass.'::'.$attribute;
371+
if (isset($this->typesCache[$key])) {
372+
return false === D70C $this->typesCache[$key] ? null : $this->typesCache[$key];
373+
}
374+
369375
if (null !== $types = $this->propertyTypeExtractor->getTypes($currentClass, $attribute)) {
370-
return $types;
376+
return $this->typesCache[$key] = $types;
371377
}
372378

373379
if (null !== $this->classDiscriminatorResolver && null !== $discriminatorMapping = $this->classDiscriminatorResolver->getMappingForClass($currentClass)) {
374380
if ($discriminatorMapping->getTypeProperty() === $attribute) {
375-
return array(
381+
return $this->typesCache[$key] = array(
376382
new Type(Type::BUILTIN_TYPE_STRING),
377383
);
378384
}
379385

380386
foreach ($discriminatorMapping->getTypesMapping() as $mappedClass) {
381387
if (null !== $types = $this->propertyTypeExtractor->getTypes($mappedClass, $attribute)) {
382-
return $types;
388+
return $this->typesCache[$key] = $types;
383389
}
384390
}
385391
}
386392

393+
$this->typesCache[$key] = false;
394+
387395
return null;
388396
}
389397

0 commit comments

Comments
 (0)
0