[Form] Removed usage of the ChoiceList::getIndicesFor*() methods where they don't offer any performance benefit
This commit is contained in:
parent
a672bba5cb
commit
e1bf07f1f9
@ -60,14 +60,14 @@ class ChoiceToBooleanArrayTransformer implements DataTransformerInterface
|
||||
throw new TransformationFailedException('Can not get the choice list', $e->getCode(), $e);
|
||||
}
|
||||
|
||||
$index = current($this->choiceList->getIndicesForChoices(array($choice)));
|
||||
$valueMap = array_flip($this->choiceList->getValuesForChoices(array($choice)));
|
||||
|
||||
foreach ($values as $i => $value) {
|
||||
$values[$i] = $i === $index;
|
||||
$values[$i] = isset($valueMap[$value]);
|
||||
}
|
||||
|
||||
if ($this->placeholderPresent) {
|
||||
$values['placeholder'] = false === $index;
|
||||
$values['placeholder'] = 0 === count($valueMap);
|
||||
}
|
||||
|
||||
return $values;
|
||||
|
@ -58,10 +58,10 @@ class ChoicesToBooleanArrayTransformer implements DataTransformerInterface
|
||||
throw new TransformationFailedException('Can not get the choice list', $e->getCode(), $e);
|
||||
}
|
||||
|
||||
$indexMap = array_flip($this->choiceList->getIndicesForChoices($array));
|
||||
$valueMap = array_flip($this->choiceList->getValuesForChoices($array));
|
||||
|
||||
foreach ($values as $i => $value) {
|
||||
$values[$i] = isset($indexMap[$i]);
|
||||
$values[$i] = isset($valueMap[$value]);
|
||||
}
|
||||
|
||||
return $values;
|
||||
|
@ -57,7 +57,7 @@ class ChoiceType extends AbstractType
|
||||
|
||||
// Check if the choices already contain the empty value
|
||||
// Only add the empty value option if this is not the case
|
||||
if (null !== $options['empty_value'] && 0 === count($options['choice_list']->getIndicesForValues(array('')))) {
|
||||
if (null !== $options['empty_value'] && 0 === count($options['choice_list']->getChoicesForValues(array('')))) {
|
||||
$placeholderView = new ChoiceView(null, '', $options['empty_value']);
|
||||
|
||||
// "placeholder" is a reserved index
|
||||
@ -120,7 +120,7 @@ class ChoiceType extends AbstractType
|
||||
|
||||
// Check if the choices already contain the empty value
|
||||
// Only add the empty value option if this is not the case
|
||||
if (null !== $options['empty_value'] && 0 === count($options['choice_list']->getIndicesForValues(array('')))) {
|
||||
if (null !== $options['empty_value'] && 0 === count($options['choice_list']->getChoicesForValues(array('')))) {
|
||||
$view->vars['empty_value'] = $options['empty_value'];
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user