[Form] Removed usage of the ChoiceList::getIndicesFor*() methods where they don't offer any performance benefit

This commit is contained in:
Bernhard Schussek 2013-05-05 23:28:39 +02:00
parent 599c86509e
commit 62fbed608a
3 changed files with 7 additions and 7 deletions

View File

@ -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;

View File

@ -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;

View File

@ -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'];
}