[Form] Removed usage of the ChoiceList::getIndicesFor*() methods where they don't offer any performance benefit
This commit is contained in:
parent
dc762e10d7
commit
53f292adcc
@ -56,10 +56,10 @@ class ChoiceToBooleanArrayTransformer implements DataTransformerInterface
|
|||||||
throw new TransformationFailedException('Can not get the choice list', $e->getCode(), $e);
|
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) {
|
foreach ($values as $i => $value) {
|
||||||
$values[$i] = $i === $index;
|
$values[$i] = isset($valueMap[$value]);
|
||||||
}
|
}
|
||||||
|
|
||||||
return $values;
|
return $values;
|
||||||
|
@ -58,10 +58,10 @@ class ChoicesToBooleanArrayTransformer implements DataTransformerInterface
|
|||||||
throw new TransformationFailedException('Can not get the choice list', $e->getCode(), $e);
|
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) {
|
foreach ($values as $i => $value) {
|
||||||
$values[$i] = isset($indexMap[$i]);
|
$values[$i] = isset($valueMap[$value]);
|
||||||
}
|
}
|
||||||
|
|
||||||
return $values;
|
return $values;
|
||||||
|
@ -104,7 +104,7 @@ class ChoiceType extends AbstractType
|
|||||||
|
|
||||||
// Check if the choices already contain the empty value
|
// Check if the choices already contain the empty value
|
||||||
// Only add the empty value option if this is not the case
|
// Only add the empty value option if this is not the case
|
||||||
if (0 === count($options['choice_list']->getIndicesForValues(array('')))) {
|
if (0 === count($options['choice_list']->getChoicesForValues(array('')))) {
|
||||||
$view->vars['empty_value'] = $options['empty_value'];
|
$view->vars['empty_value'] = $options['empty_value'];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user