[Serializer] Reduce complexity of NameConverter
Cleaner and faster implementation of camelcase normalization. Speed improvement is particularly visible in long string input.
This commit is contained in:
parent
64ec5c5faf
commit
50ca944278
@ -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