Review main Merged

78127[TASK] Introduce Map data-structure

Oliver Hader CR +2 V +2 Normal +227 −0 updated 03/15/23, 08:53

Commit message

Unfortunately PHP emphasizes "weak" over "map" in their new PHP 8
data-structure `\WeakMap`. As a result it cannot be passed to other
functions that would enrich an existing `\WeakMap` - since objects
created in that function scope would not exist outside and thus
directly trigger garbage collection of `\WeakMap`.

`\SplObjectStorage` has a strange behavior when using an iteration
like `foreach ($map as $key => $value)` - the `$value` is actually
the `$key` for BC reasons.

As a substitute, `\TYPO3\CMS\Core\Type\Map` is introduced which has a
similar behavior and got an additional `Map::fromEntries()` factory.
It acts as a wrapper of `\SplObjectStorage` with reduced features.

Example:

$map = new \TYPO3\CMS\Core\Type\Map();
$key = new \stdClass();
$value = new \stdClass();
$map[$key] = $value;

foreach ($map as $key => $value) { ... }

Review

  • Code review CR +2 Done
    • Oliver Hader +2
    • Andreas Kienast +1
    • Benni Mack +1
  • Verified V +2 Done
    • Oliver Hader +2
    • Andreas Kienast +1
    • Benni Mack +1
    • core-ci +1 CI

Issues 1

Files 2

Review log 1621

  1. Oliver Hader uploaded patch set 1 03/14/23, 21:17

  2. Oliver Hader uploaded patch set 2 03/14/23, 21:25

  3. core-ci voted on patch set 1 V +1 03/14/23, 21:25 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/38947

  4. core-ci voted on patch set 2 V +1 03/14/23, 21:32 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/38948

  5. Benni Mack updated the commit message in patch set 3 V +1 03/14/23, 21:37

  6. Benni Mack voted on patch set 3 V +1 CR +1 03/14/23, 21:37

  7. Markus Klein updated the commit message in patch set 4 CR +1 V +1 03/14/23, 21:41

  8. Markus Klein commented on patch set 4 03/14/23, 21:44

  9. core-ci voted on patch set 3 V +1 03/14/23, 21:47 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/38949

  10. core-ci voted on patch set 4 V +1 03/14/23, 21:51 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/38952

  11. Oliver Hader commented on patch set 4 03/14/23, 22:00

    Reply

    Good point, seems I got confused with not using `spl_object_id` like mentioned in https://wiki.php.net/rfc/weak_maps - thus, I did not consider SPL at all.
  12. Oliver Hader commented on patch set 4 CR -1 03/14/23, 22:02

    I'll check the CSP stuff with SplObjectStorage...
  13. Oliver Hader commented on patch set 4 03/14/23, 22:17

    `SplObjectStorage` has a strange behavior with `foreach`, see https://3v4l.org/gloDO#v8.1.16
  14. Oliver Hader commented on patch set 4 03/14/23, 22:39

    The hint on `SplObjectStorage` was good, by using the new `Map` as wrapper we get the benefits of the internal implementation in terms of speed and can make it flexible towards iterations with `foreach`.
  15. Oliver Hader uploaded patch set 5 CR -1 V +1 03/14/23, 22:40

  16. core-ci voted on patch set 5 V +1 03/14/23, 22:49 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/38953

  17. Oliver Hader commented on patch set 5 03/14/23, 22:50

    Reply

    Done

    Reply

    Done
  18. Andreas Kienast voted on patch set 5 V +1 CR +1 03/15/23, 07:14

  19. Benni Mack voted on patch set 5 V +1 CR +1 03/15/23, 07:29

  20. Oliver Hader voted on patch set 5 V +2 CR +2 03/15/23, 08:53

  21. Oliver Hader merged patch set 6 03/15/23, 08:53