Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit53ffa66

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 | MITCheck ticket for descriptionCommits-------4224145 [Serializer] AbstractObjectNormalizer improve perf when checking types
2 parents6cc2bd6 +4224145 commit53ffa66

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
constDISABLE_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
returnnull;
367368
}
368369

370+
$key =$currentClass.'::'.$attribute;
371+
if (isset($this->typesCache[$key])) {
372+
returnfalse ===$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-
returnarray(
381+
return$this->typesCache[$key] =array(
376382
newType(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
returnnull;
388396
}
389397

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp