Navigation Menu

Skip to content

Commit

Permalink
feature #28277 [Serializer] AbstractObjectNormalizer improve performa…
Browse files Browse the repository at this point in the history
…nce (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
  • Loading branch information
fabpot committed Aug 27, 2018
2 parents 6cc2bd6 + 4224145 commit 53ffa66
Showing 1 changed file with 11 additions and 3 deletions.
Expand Up @@ -37,6 +37,7 @@ abstract class AbstractObjectNormalizer extends AbstractNormalizer
const DISABLE_TYPE_ENFORCEMENT = 'disable_type_enforcement';

private $propertyTypeExtractor;
private $typesCache = array();
private $attributesCache = array();

/**
Expand Down Expand Up @@ -366,24 +367,31 @@ private function getTypes(string $currentClass, string $attribute)
return null;
}

$key = $currentClass.'::'.$attribute;
if (isset($this->typesCache[$key])) {
return false === $this->typesCache[$key] ? null : $this->typesCache[$key];
}

if (null !== $types = $this->propertyTypeExtractor->getTypes($currentClass, $attribute)) {
return $types;
return $this->typesCache[$key] = $types;
}

if (null !== $this->classDiscriminatorResolver && null !== $discriminatorMapping = $this->classDiscriminatorResolver->getMappingForClass($currentClass)) {
if ($discriminatorMapping->getTypeProperty() === $attribute) {
return array(
return $this->typesCache[$key] = array(
new Type(Type::BUILTIN_TYPE_STRING),
);
}

foreach ($discriminatorMapping->getTypesMapping() as $mappedClass) {
if (null !== $types = $this->propertyTypeExtractor->getTypes($mappedClass, $attribute)) {
return $types;
return $this->typesCache[$key] = $types;
}
}
}

$this->typesCache[$key] = false;

return null;
}

Expand Down

0 comments on commit 53ffa66

Please sign in to comment.