minor #21676 [Serializer] Reduce complexity of NameConverter (gadelat)
This PR was merged into the 3.3-dev branch.
Discussion
----------
[Serializer] Reduce complexity of NameConverter
Cleaner and faster implementation of camelcase normalization.
Speed improvement is particularly visible in long string input.
| Q | A
| ------------- | ---
| Branch? | master
| Bug fix? | no
| New feature? | no
| BC breaks? | no
| Deprecations? | no
| Tests pass? | yes
| Fixed tickets | -
| License | MIT
| Doc PR | -
Commits
-------
50ca944278
[Serializer] Reduce complexity of NameConverter
This commit is contained in:
commit
f4db331478
@ -44,19 +44,7 @@ class CamelCaseToSnakeCaseNameConverter implements NameConverterInterface
|
||||
public function normalize($propertyName)
|
||||
{
|
||||
if (null === $this->attributes || in_array($propertyName, $this->attributes)) {
|
||||
$lcPropertyName = lcfirst($propertyName);
|
||||
$snakeCasedName = '';
|
||||
|
||||
$len = strlen($lcPropertyName);
|
||||
for ($i = 0; $i < $len; ++$i) {
|
||||
if (ctype_upper($lcPropertyName[$i])) {
|
||||
$snakeCasedName .= '_'.strtolower($lcPropertyName[$i]);
|
||||
} else {
|
||||
$snakeCasedName .= strtolower($lcPropertyName[$i]);
|
||||
}
|
||||
}
|
||||
|
||||
return $snakeCasedName;
|
||||
return strtolower(preg_replace('/[A-Z]/', '_\\0', lcfirst($propertyName)));
|
||||
}
|
||||
|
||||
return $propertyName;
|
||||
|
Reference in New Issue
Block a user