Review main Merged

89294[TASK] Evaluate item value only once in fieldMap Element

Oli Bartsch CR +2 V +2 Easy +2 −1 updated 05/13/25, 07:57

Commit message

Review

  • Code review CR +2 Done
    • Oli Bartsch +2
    • Stefan Bürk +1
    • Sven Liebert +1
  • Verified V +2 Done
    • Oli Bartsch +2
    • Stefan Bürk +1
    • Sven Liebert +1
    • core-ci +1 CI

Issues 1

Files 1

Review log 1821

  1. Oli Bartsch uploaded patch set 1 05/04/25, 21:04

  2. core-ci voted on patch set 1 V +1 05/04/25, 21:10 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/78497

  3. Stefan Bürk commented on patch set 1 05/04/25, 22:32

    FieldMapElement.php:56

    ```suggestion if (is_array($columns) && $columns !== []) { $itemValueIsArray = is_array($itemValue); ``` Issue/commit message is quite spare to give background on this. First, I'm curious if `$itemValue` aka `$parameterArray['itemFormElValue']` can be `not an array` at all. If that is the case, I would say that this change is now a change in behaviour. TBH Could not produce a constelation having $itemValue not an array so far. I guess, we can make the "check" only once into a variable and use that at the place it has been checked before to keep the field(s) rendering evenwith empty values in case $itemValues is not an array. Current change will avoid rendering all the input fields in that case. And I would postulate that moving the check has no real performance implication as long not hunderts or thousands of fields would be rendered - but still doing it once but still checking to determine it once for the value below from a bool var is okay albeit neglitable. The move to this condition changes the behaviour drastically, and if that is intented this should be at least described and argued in the commit message. Is it possible to reproduce this with a `!is_array($itemValue)` in some way ?

    FieldMapElement.php:62

    ```suggestion $fieldValue = $itemValueIsArray && isset($itemValue[$fieldName]) ? htmlspecialchars((string)$itemValue[$fieldName]) : ''; ```
  4. Stefan Bürk commented on patch set 1 05/04/25, 22:43

    FieldMapElement.php:62 Reply

    Alternativly, we can make the check before the condition in L56 and set `$itemValue` to an empty array in case it is not an array and have an array ensured that way.
  5. Oli Bartsch uploaded patch set 2 V +1 05/05/25, 10:19

  6. Oli Bartsch commented on patch set 2 05/05/25, 10:20

    FieldMapElement.php:56 Reply

    You are totally right, thank you! I've adjusted according to your suggestion.

    FieldMapElement.php:62 Reply

    Done
  7. core-ci voted on patch set 2 V +1 05/05/25, 10:29 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/78517

  8. Stefan Bürk voted on patch set 2 CR +1 V +1 05/05/25, 13:06

  9. Stefan Bürk commented on patch set 2 05/05/25, 13:14

    FieldMapElement.php:62 Reply

    Thanks for adopting.
  10. Sven Liebert voted on patch set 2 CR +1 V +1 05/05/25, 20:43

  11. Benjamin Franzke commented on patch set 2 CR -1 05/05/25, 20:46

    FieldMapElement.php:57

    This creates an unnecessary empty array. This array is only used as a fallback and therefore wastes RAM. Why not a fallback to `null`?
  12. Oli Bartsch commented on patch set 2 05/05/25, 20:56

    FieldMapElement.php:57 Reply

    This isn't RAM wastage—it's clarity. The variable is meant to be an array. Falling back to null just to save 0.0000012 MB of memory sounds like optimizing the air resistance on a parked car. Besides: [] makes the intent explicit → This is an array, even when it’s empty. It avoids unnecessary if(is_array($itemValue)) spaghetti later. It keeps the code consistent and prevents surprises for the next dev (which could be Future You™). Most importantly: empty arrays don’t break loops. Null does. That’s a pretty harsh way to save a byte. So yes, we're allocating an empty array—for performance, readability, and because our dignity as developers demands it.
  13. Benjamin Franzke commented on patch set 2 05/06/25, 09:26

    FieldMapElement.php:57 Reply

    > It avoids unnecessary if(is_array($itemValue)) spaghetti later. `is_array()` is not needed, since you can call `isset(…['foo'])` on `null`.
  14. Oli Bartsch commented on patch set 2 05/06/25, 10:08

    FieldMapElement.php:57 Reply

    Sure, but $itemValue is expected to be an array in this element. We should therefore IMO not do type changes on runtime as that makes following the code harder. Btw. I'm pleased to admit that this is not a no brainer.
  15. Oli Bartsch commented on patch set 2 05/08/25, 14:22

    FieldMapElement.php:57 Reply

    Done
  16. Oli Bartsch rebased onto patch set 3 CR +1 V +1 05/12/25, 13:56

  17. core-ci voted on patch set 3 V +1 05/12/25, 14:02 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/78804

  18. Stefan Bürk voted on patch set 3 CR +1 V +1 05/13/25, 07:33

  19. Sven Liebert voted on patch set 3 CR +1 V +1 05/13/25, 07:48

  20. Oli Bartsch voted on patch set 3 CR +2 V +2 05/13/25, 07:57

  21. Oli Bartsch merged patch set 4 05/13/25, 07:57