8000 [Form] Removed usage of the ChoiceList::getIndicesFor*() methods wher… · symfony/symfony@e1bf07f · GitHub
[go: up one dir, main page]

Skip to content

Commit e1bf07f

Browse files
committed
[Form] Removed usage of the ChoiceList::getIndicesFor*() methods where they don't offer any performance benefit
1 parent a672bba commit e1bf07f

File tree

3 files changed

+7
-7
lines changed

3 files changed

+7
-7
lines changed

src/Symfony/Component/Form/Extension/Core/DataTransformer/ChoiceToBooleanArrayTransformer.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -60,14 +60,14 @@ public function transform($choice)
6060
throw new TransformationFailedException('Can not get the choice list', $e->getCode(), $e);
6161
}
6262

63-
$index = current($this->choiceList->getIndice 8000 sForChoices(array($choice)));
63+
$valueMap = array_flip($this->choiceList->getValuesForChoices(array($choice)));
6464

6565
foreach ($values as $i => $value) {
66-
$values[$i] = $i === $index;
66+
$values[$i] = isset($valueMap[$value]);
6767
}
6868

6969
if ($this->placeholderPresent) {
70-
$values['placeholder'] = false === $index;
70+
$values['placeholder'] = 0 === count($valueMap);
7171
}
7272

7373
return $values;

src/Symfony/Component/Form/Extension/Core/DataTransformer/ChoicesToBooleanArrayTransformer.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,10 +58,10 @@ public function transform($array)
5858
throw new TransformationFailedException('Can not get the choice list', $e->getCode(), $e);
5959
}
6060

61-
$indexMap = array_flip($this->choiceList->getIndicesForChoices($array));
61+
$valueMap = array_flip($this->choiceList->getValuesForChoices($array));
6262

6363
foreach ($values as $i => $value) {
64-
$values[$i] = isset($indexMap[$i]);
64+
$values[$i] = isset($valueMap[$value]);
6565
}
6666

6767
return $values;

src/Symfony/Component/Form/Extension/Core/Type/ChoiceType.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ public function buildForm(FormBuilderInterface $builder, array $options)
5757

5858
// Check if the choices already contain the empty value
5959
// Only add the empty value option if this is not the case
60-
if (null !== $options['empty_value'] && 0 === count($options['choice_list']->getIndicesForValues(array('')))) {
60+
if (null !== $options['empty_value'] && 0 === count($options['choice_list']->getChoicesForValues(array('')))) {
6161
$placeholderView = new ChoiceView(null, '', $options['empty_value']);
6262

6363
// "placeholder" is a reserved index
@@ -120,7 +120,7 @@ public function buildView(FormView $view, FormInterface $form, array $options)
120120

121121
// Check if the choices already contain the empty value
122122
// Only add the empty value option if this is not the case
123-
if (null !== $options['empty_value'] && 0 === count($options['choice_list']->getIndicesForValues(array('')))) {
123+
if (null !== $options['empty_value'] && 0 === count($options['choice_list']->getChoicesForValues(array('')))) {
124124
$view->vars['empty_value'] = $options['empty_value'];
125125
}
126126

0 commit comments

Comments
 (0)
0