mirror of
https://github.com/facebook/react-native.git
synced 2025-11-01 09:14:26 +00:00
Summary: `traitCast` is a special form of static_cast that checks additional requirements (similar to `dynamic_cast`) before performing the cast. We will use that in many places in the coming diffs. Restructuring the class hierarchy in the previous diff finally allows us to do static casts among ShadowNode and LayoutableShadowNode and other classes (previously it wasn't allowed because of lack of common base class). Why we don't want to use `dynamic_cast`: * It's expensive (and we need to do the cast on the hottest fragments of the framework). (See: (1) http://www.stroustrup.com/fast_dynamic_casting.pdf and (2) https://www.youtube.com/watch?v=ARYP83yNAWk Herb Sutter & proposal of `down_cast`). * It's code-size inefficient, whereas `static_cast` has zero runtime and code-size overhead. * Removing `dynamic_cast` will allow us finally to opt-out `RTTI` (additional code size and perm wins). Changelog: [Internal] Fabric-specific internal change. Reviewed By: sammy-SC Differential Revision: D20052024 fbshipit-source-id: d293c1cf80deb7817d333d5306d6b32bf3abdb27