Commit Graph

1147 Commits

Author SHA1 Message Date
David Aurelio d8fcb7f165 Use bitfields for `YGLayout` and `YGNode`
Summary:
@public

Further heap size reductions by using bitfields in `YGLayout` and `YGNode`.

Reviewed By: SidharthGuglani

Differential Revision: D13466325

fbshipit-source-id: ddcef0a1b3822e7449fe485d99c920d54139c893
2018-12-18 08:15:09 -08:00
David Aurelio ac94e54f5a Switch storage in `YGStyle` to `CompactValue`
Summary:
@public

Switches the storage in `facebook::yoga::detail::Values` from `YGValue` to `facebook::yoga::detail::CompactValue`.
This cuts heap size for arrays of values in half.

Reviewed By: SidharthGuglani

Differential Revision: D13465586

fbshipit-source-id: 49a4d6d29a73bdd44843b1f3c57bf746050c94d6
2018-12-18 08:15:09 -08:00
David Aurelio 375311091c Decouple from storage type in `YGStyle`
Summary:
@public

The storage format of `YGValue` in `YGStyle` is an implementation detail that is going to change soon. It is only guaranteed to be assignable from, and castable to `YGValue`.
Here, we remove tight coupling from the actual implementation in React Native.

Reviewed By: shergin

Differential Revision: D13465113

fbshipit-source-id: 41dfcb90c2a1cd825a6732854bf84d4c3318d835
2018-12-18 02:47:10 -08:00
David Aurelio 0eeb94e948 Remove cast from `detail::Values` to `std::array<YGValue`
Summary:
@public

When switching to `CompactValue`, casting edges or dimensions to `std::array<YGValue, ...>` will do actual work.
In order to avoid that from happening implicitely, we remove the casting operator.

Reviewed By: SidharthGuglani

Differential Revision: D13464292

fbshipit-source-id: 217065b001a63cfa8adde715063682c583007a4d
2018-12-14 09:23:13 -08:00
David Aurelio dac59586ed Encapsulate arrays of `YGValue` within `YGStyle`
Summary:
@public

Enforce more encapsulation of arrays of `YGValue` in `YGSty;e`.
This will allow us to use `CompactValue` in `YGStyle` while (mostly) retaining API compatibility.

Reviewed By: SidharthGuglani

Differential Revision: D13452042

fbshipit-source-id: 382b1c7245c4bea4280126ab1413e7e931b62eaa
2018-12-14 09:23:13 -08:00
David Aurelio 94dd6025d3 Introduce `CompactValue`
Summary:
@public

`CompactValue` represents a `YGValue` in 32bits instead of 64. This comes at the cost of a range limitation, as one exponent bit is borrowed for the unit.

*Undefined* and *Auto* have no magnitude, and are represented as *NaN* values.

The data structure is meant to be used as a field type on `YGStyle` to save memory.

This is header-only for efficient inlining.

Reviewed By: jackerghan, aCorrado

Differential Revision: D13187211

fbshipit-source-id: 16e3ffad592e38e2493e4f7c8b952d372e449846
2018-12-14 09:23:13 -08:00
Rick Hanlon e7cf870e31 Fix textDecorationLine property
Summary:
This diff fixes a style property that was incorrectly mapped as `textDecorationLineType` in Fabric

This was correctly mapped in classic here: diffusion/FBS/browse/master/xplat/js/react-native-github/Libraries/Text/BaseText/RCTBaseTextViewManager.m;10b92f1847cdec8a3f0a996f218989766516f805$48

Reviewed By: mdvacca

Differential Revision: D13443921

fbshipit-source-id: 7fafaf2492d8c3b938f2e433a983303958e5c578
2018-12-13 14:02:15 -08:00
David Aurelio d0485b2f04 Don't use `default` in exhaustive switch
Summary:
@public
removes the `default` case from an already exhaustive switch.

Reviewed By: SidharthGuglani

Differential Revision: D13451869

fbshipit-source-id: 32727330c7fce013963f5c83c95a73b230d5c938
2018-12-13 10:42:51 -08:00
David Aurelio a816c0321c Don't pass `std::string` by pointer
Summary:
@public

Pass strings by mutable ref rather than pointer.

Reviewed By: SidharthGuglani

Differential Revision: D13439613

fbshipit-source-id: ea889abe0fe8ec44ae02f13c1d9a10c0dbfdbcf1
2018-12-13 07:16:46 -08:00
David Aurelio 206705892f Use bitfields for enum members of `YGStyle`
Summary:
@public

Puts all enum fields of `YGStyle` into bitfields. This saves 36 bytes (> 3%) per node.

Reviewed By: SidharthGuglani

Differential Revision: D13439606

fbshipit-source-id: b60a5444762041bc6f8cc5e04757034cb6893b30
2018-12-13 07:16:46 -08:00
David Aurelio bb1b80b763 Remove templates for setting/getting style properties
Summary:
@public

Replaces the `StyleProp` template with a simple setter macro / inlined getter code.

The template was introduced to replace more extensive macros that would generate function signatures, too.
Here, we keep the spirit of that change by only generating function bodies.

Reviewed By: SidharthGuglani

Differential Revision: D13439612

fbshipit-source-id: 36f6a86917d035be6891cb736d1f288d8e02f5cf
2018-12-13 07:16:46 -08:00
David Aurelio 05d90c3013 `YGNodeBoundAxisWithinMinAndMax` accepts `YGFloatOptional`
Summary:
@public

Saves some calls to `.unwrap()`

Reviewed By: SidharthGuglani

Differential Revision: D13439600

fbshipit-source-id: ce0f6bad9a0709e9d64e23d8349bc2423b9b2ad4
2018-12-13 07:16:46 -08:00
David Aurelio 3e3972628c Remove unnecessary `static` keyword
Summary:
@public

Header-declared inline functions shouldn’t be decleared `static`

Reviewed By: SidharthGuglani

Differential Revision: D13439607

fbshipit-source-id: 89555bb19a3fff6e29ca4afc10fe15fecca8fa17
2018-12-13 07:16:46 -08:00
David Aurelio 41c326ee9f Get rid of `static_cast` in `YGResolveValue`
Summary:
@public

Removes `static_cast` from `YGResolveValue`

Reviewed By: SidharthGuglani

Differential Revision: D13439605

fbshipit-source-id: 8736541c8e1d43fd698d368cb4f3211ffd929364
2018-12-13 07:16:46 -08:00
David Aurelio a56b67fa9b Inline `YGFloatOptional` completely
Summary:
@public
`YGFLoatOptional` only contains trivial functionality. Make it header-only.

Reviewed By: SidharthGuglani

Differential Revision: D13439609

fbshipit-source-id: 3f3c6c3a15e05ac55da2af30eb629f786ecb90a9
2018-12-13 07:16:45 -08:00
David Aurelio 688b3195c3 Pass `YGFloatOptional` by value, not reference
Summary:
@public

`YGFloatOptional` is a 32bit type now, and can be passed by value efficiently.

Reviewed By: SidharthGuglani

Differential Revision: D13439603

fbshipit-source-id: e12539ad5b3cccbd5bc27869866ca66c023b24a7
2018-12-13 07:16:45 -08:00
David Aurelio ada4831580 Eliminate `YGFloatOptional::getValue()`
Summary:
@public

Replace `YGFloatOptional::getValue()` with `YGFloatOptional::unwrap()`.

`YGFloatOptional::getValue()` has the unfortunate property of calling `std::exit` if the wrapped value is undefined.

Here, we eliminate the method, and just call `.unwrap()` everywhere.

Reviewed By: shergin

Differential Revision: D13439608

fbshipit-source-id: 5ae82b170537d0a10c301412567a7a66fd50bab4
2018-12-13 07:16:45 -08:00
David Aurelio 110c1c260f Remove `YGUnwrapFloatOptional`
Summary:
Replaces `YGUnwrapFloatOptional` with `YGFloatOptional::unwrap`.

This leads to more idiomatic C++, and to less function call nesting, thus increasing readability.

Reviewed By: SidharthGuglani

Differential Revision: D13439604

fbshipit-source-id: 33b43c08d725c253c359959e7cbbd83fd6bd9ba4
2018-12-13 07:16:45 -08:00
David Aurelio f90c2fb3f6 Store `YGFloatOptional` in 32 bits
Summary:
@public

After removing `-ffast-math`, `NaN` can again be used to represent `undefined`. That allows us to remove the additional flag from `YGFloatOptional`, and reduce memory usage.

Reviewed By: SidharthGuglani

Differential Revision: D13439611

fbshipit-source-id: 93e90f72f0415edb228b4e7d145e1fae35cc6b43
2018-12-13 07:16:45 -08:00
David Aurelio 2d6a10028f Add tests for `YGFloatOptional`
Summary:
@public

Adds tests for `YGFloatOptional`, to ease refactorings.

Reviewed By: SidharthGuglani

Differential Revision: D13439610

fbshipit-source-id: e29da7f85ccedc46520b59f6c893bad521d35417
2018-12-13 07:16:45 -08:00
David Aurelio 568472231f Make equality operator for `YGValue` inlineable
Summary:
@public

Makes `operator==` for `YGValue` an inline function.

Reviewed By: SidharthGuglani

Differential Revision: D13439601

fbshipit-source-id: c5dd1f35c40f0ffa8224ee2f40ac7cc3cd8e3cf9
2018-12-13 07:16:45 -08:00
David Aurelio b5c66a3fbe Move out `YGValue`
Summary:
@public

Creates a single header file for `YGValue`. This is in preparation of a more compact representation of `YGValue` within `YGStyle`.

Also fixes the incorrect definition of NAN.

Reviewed By: SidharthGuglani

Differential Revision: D13439602

fbshipit-source-id: 68eef2c391b6c9810f3c995b86fff7204ebe6511
2018-12-13 07:16:45 -08:00
David Aurelio 6f70d4c0ac Roll back `-ffast-math`
Summary:
@public

`-ffast-math` does not have measurable performance benefits.

By using `NaN` for *undefined* values again, we can squeeze `YGFloatOptional` into 32 bits.
This will also enable us to store `YGValue` (or a variant of it) in 32 bits.

Reviewed By: astreet

Differential Revision: D13403925

fbshipit-source-id: b13d026bf556f24ab4699e65fb450af13a70961b
2018-12-13 07:16:45 -08:00
David Aurelio 1decf879f8 Back out "[yoga][PR] Fix aspect ratio when stretching with main axis margin"
Summary: Original commit changeset: 6970e6072e79

Reviewed By: mdvacca

Differential Revision: D13437552

fbshipit-source-id: 65a55d716da6b6582e38efa906d3f540e58418bf
2018-12-12 16:20:45 -08:00
Emil Sjölander ee6b0d6658 Fix aspect ratio when stretching with main axis margin (#834)
Summary:
I've noticed that when a child's size is determined by `align-items: stretch` in combination with `aspect-ratio` its size is wrongly calculated to account for margin in the main axis when there is more than enough space.

See playground: https://goo.gl/tgW6cD

I've yet to figure out exactly how to solve this but i've started by writing a failing test when can be seen in the first commit here.

I assumed I had found the bug here https://github.com/facebook/yoga/blob/master/yoga/Yoga.cpp#L1838 where margin is being subtracted from the desired width even though the measure mode tells it to measure to exactly that size. However, if we don't remove this margin from the available width then 15 tests fail (including the one I just added) not quite figured out why yet. I'm also a bit confused at to why this would only happen for nodes with `aspect-ratio` and not for nodes where an explicit height and width is set.
Pull Request resolved: https://github.com/facebook/yoga/pull/834

Reviewed By: astreet

Differential Revision: D13223579

Pulled By: davidaurelio

fbshipit-source-id: 6970e6072e79f3bb6f9097355ab6e441441bfd88
2018-12-10 09:23:01 -08:00
Taras Tsugrii 7fb02889d7 Buildify xplat build files.
Summary: drop-conflicts

Differential Revision: D13378356

fbshipit-source-id: 555bcfb30139b165e32e2045b291249c6b6b8650
2018-12-08 13:18:23 -08:00
David Aurelio 90f582ffb9 Back out Stack D13119110..D13236159
Summary: backout, causes failures

Reviewed By: adityasharat

Differential Revision: D13376210

fbshipit-source-id: 1fa8823f2dce601c47738f34ddb2674288197e79
2018-12-07 13:01:28 -08:00
Doug Russell ee7c702308 Accessibility Escape
Summary: Pull Request resolved: https://github.com/facebook/react-native/pull/22047

Differential Revision: D13146179

Pulled By: cpojer

fbshipit-source-id: b8a089114a5deafee47dd482e484d413c8c39137
2018-12-06 19:44:21 -08:00
David Aurelio 8f6521aacf Don't pass `std::string` by pointer
Summary:
@public

Pass strings by mutable ref rather than pointer.

Reviewed By: SidharthGuglani

Differential Revision: D13236159

fbshipit-source-id: 04fd35e8a9e106ba8cdd71cfab31e8d90edaac9e
2018-12-06 07:38:44 -08:00
David Aurelio 32d5da2eb8 Use bitfields for enum members of `YGStyle`
Summary:
@public

Puts all enum fields of `YGStyle` into bitfields. This saves 36 bytes (> 3%) per node.

Reviewed By: SidharthGuglani

Differential Revision: D13233686

fbshipit-source-id: 3ef7e0d6913f0254806acb942d9a9f5b78a5af9c
2018-12-06 07:38:44 -08:00
David Aurelio 32bc724fb0 Remove templates for setting/getting style properties
Summary:
@public

Replaces the `StyleProp` template with a simple setter macro / inlined getter code.

The template was introduced to replace more extensive macros that would generate function signatures, too.
Here, we keep the spirit of that change by only generating function bodies.

Reviewed By: SidharthGuglani

Differential Revision: D13233687

fbshipit-source-id: 218a7d5edb489b43a66c8c9d6156f74feefd2227
2018-12-06 07:38:44 -08:00
David Aurelio f9c575e352 `YGNodeBoundAxisWithinMinAndMax` accepts `YGFloatOptional`
Summary:
@public

Saves some calls to `.unwrap()`

Reviewed By: SidharthGuglani

Differential Revision: D13209153

fbshipit-source-id: 5658586e91496085f39b3522db6364aaeafcfe2f
2018-12-06 07:38:44 -08:00
David Aurelio 94ab9b429c inline `YGUnwrapFloatOptional`
Summary:
@public
Replaces C-style function call with C++ method invokation.

Reviewed By: SidharthGuglani

Differential Revision: D13209154

fbshipit-source-id: 14e650af4655efb3a659f3cd949a11df773aabcf
2018-12-06 07:38:44 -08:00
David Aurelio 517d07ddcf Remove unnecessary `static` keyword
Summary:
@public

Header-declared inline functions shouldn’t be decleared `static`

Reviewed By: SidharthGuglani

Differential Revision: D13209156

fbshipit-source-id: e2d643a67e6f6c33c96dc71b0a90d00bd9b6f36f
2018-12-06 07:38:44 -08:00
David Aurelio fa171b4fe7 Get rid of `static_cast` in `YGResolveValue`
Summary:
@public

Removes `static_cast` from `YGResolveValue`

Reviewed By: SidharthGuglani

Differential Revision: D13209155

fbshipit-source-id: 76c27c89f6217af9dfef9e2620d639c9f3e212f5
2018-12-06 07:38:43 -08:00
David Aurelio ceb6602422 Inline `YGFloatOptional` completely
Summary:
@public
`YGFLoatOptional` only contains trivial functionality. Make it header-only.

Reviewed By: SidharthGuglani

Differential Revision: D13209151

fbshipit-source-id: 3ecca015fa0ac6644ae694b44bc53d840fbc5635
2018-12-06 07:38:43 -08:00
David Aurelio a7757f6e5d Pass `YGFloatOptional` by value, not reference
Summary:
@public

`YGFloatOptional` is a 32bit type now, and can be passed by value efficiently.

Reviewed By: SidharthGuglani

Differential Revision: D13209150

fbshipit-source-id: c7b937a640258256c97e082ba2f832754e191b9a
2018-12-06 07:38:43 -08:00
David Aurelio 4157a49d8d Eliminate `YGFloatOptional::getValue()`
Summary:
@public

`YGFloatOptional::getValue()` has the unfortunate property of calling `std::exit` if the wrapped value is undefined.
That forces `x.isUndefined() ? fallback : x.getValue()` as access pattern.

Here, we replace that by introducing `YGFloatOptional::orElse(float)` which encapsulates that pattern. Other additions are `orElseGet([] { … })` and some extra operators.

Reviewed By: SidharthGuglani

Differential Revision: D13209152

fbshipit-source-id: 4e5deceaaaaf8eaed44846a8c152cc8b235e815c
2018-12-06 07:38:43 -08:00
David Aurelio cb7a9b2057 Store `YGFloatOptional` in 32 bits
Summary:
@public

After removing `-ffast-math`, `NaN` can again be used to represent `undefined`. That allows us to remove the additional flag from `YGFloatOptional`, and reduce memory usage.

Reviewed By: SidharthGuglani

Differential Revision: D13209157

fbshipit-source-id: 21b83c837a78f924a4ec23a9236ca2440b3c8606
2018-12-06 07:38:43 -08:00
David Aurelio e1c651340b Make equality operator for `YGValue` inlineable
Summary:
@public

Makes `operator==` for `YGValue` an inline function.

Reviewed By: SidharthGuglani

Differential Revision: D13189356

fbshipit-source-id: 7fe61035acf635e22ebb1a1071925d6b3dad0616
2018-12-06 07:38:43 -08:00
David Aurelio c37826a933 Move out `YGValue`
Summary:
@public

Creates a single header file for `YGValue`. This is in preparation of a more compact representation of `YGValue` within `YGStyle`.

Also fixes the incorrect definition of NAN.

Reviewed By: SidharthGuglani

Differential Revision: D13172444

fbshipit-source-id: 4250dbcf8fe15ec3ecdee3913360a73bab633ce3
2018-12-06 07:38:43 -08:00
David Aurelio 57a38263bf Roll back `-ffast-math`
Summary:
@public

`-ffast-math` does not have measurable performance benefits.

By using `NaN` for *undefined* values again, we can squeeze `YGFloatOptional` into 32 bits.
This will also enable us to store `YGValue` (or a variant of it) in 32 bits.

Reviewed By: SidharthGuglani

Differential Revision: D13119110

fbshipit-source-id: 4e6964240bf74ebc22d8783107b89d536a1a0842
2018-12-06 07:38:43 -08:00
Marc Horowitz 3f0f25f73c Back out "Check for thread consistency in JSCRuntime"
Summary:
This check is too aggressive.  We will consider putting it back once we are
more certain nothing will trigger it.

Differential Revision: D13350907

fbshipit-source-id: 6033bdbfe7adb2a18bdf889c090cf271497605e5
2018-12-05 16:59:31 -08:00
Kevin Gozali 01d7aad548 Guard calls to debug features in fabric test
Summary:
In some setup, buck cxx test for android runs with `NDEBUG` set, hence we can't call debug symbols in the test cases. So guard those callsites with `#ifndef NDEBUG`.

Also, some dependencies for this test target depend on Android specific symbols, so we have to mark it as instrumentation test for now (FB-specific).

Reviewed By: sahrens

Differential Revision: D13337637

fbshipit-source-id: 02ff152df9937f2b0b8596f53789cdee8ee8a539
2018-12-05 15:03:27 -08:00
Kevin Gozali 4f9a3bc8f6 xplat: pass through config object to fabric UIManager layer
Summary: For configuration purpose, pass down config object from the hosting app and use it in UITemplateProcessor.

Reviewed By: sahrens

Differential Revision: D13290322

fbshipit-source-id: 8bb6d7f5a3f977b873e548e15603259876b46dc8
2018-12-05 15:03:27 -08:00
Kevin Gozali 3b6f229eb9 xplat: added ReactNativeConfig to access runtime specific config values
Summary: Each app may provide different impl for its runtime specific behaviors, then Fabric and other new infra can share the same config instance to configure stuffs.

Reviewed By: sahrens

Differential Revision: D13290319

fbshipit-source-id: 30e3eeedc6ff6ef250ed233b27e38cb7c1062b55
2018-12-05 15:03:27 -08:00
Marc Horowitz 424d4458d7 Delete dead code
Summary: It was made dead by the previous revisions

Reviewed By: amnn

Differential Revision: D13313263

fbshipit-source-id: b8c8402b5427dc5d3efbbd2ee871aebf1e14ee0d
2018-12-04 12:01:59 -08:00
Marc Horowitz bdb084e8a8 Check for thread consistency in JSCRuntime
Summary:
In the version of JSC on iOS 11, creating a JSContext on one
thread and using it on another can trigger subtle and nearly
impossible to debug reentrancy-related crashes in the VM (see
https://bugs.webkit.org/show_bug.cgi?id=186827).  In !NDEBUG builds,
check for this case and throw an exception, so it can be detected
early.

Reviewed By: amnn

Differential Revision: D13313264

fbshipit-source-id: ee85435c20e23c8520495ce743d2f91f2eeada5c
2018-12-04 12:01:59 -08:00
Valentin Shergin 757518edba Fabric: `ShadowTreeRegistry::get` was renamed to `ShadowTreeRegistry::visit`
Summary: Trivial. The name `visit` expresss intent more clearly and fits C++17 `std::visit` pattern.

Reviewed By: mdvacca

Differential Revision: D13269744

fbshipit-source-id: 6aa6569c58aa66673e3f3a1662390a74290b8e01
2018-11-30 17:29:31 -08:00
Valentin Shergin d150cbc298 Fabric: Using RW-like shared lock in ShadowTreeRegistry
Summary:
`ShadowTree` class is already thread-safe, so we don't need to (we should not) guard concurent access to it.
We should guard concurrent write-access to the collection of them though.
Note that unordered_map is "thread-compatible" collection, so concurrent reading access is okay.

Reviewed By: mdvacca

Differential Revision: D13269745

fbshipit-source-id: 4779626018da0e42b81a835e538f6c1d1a8e25f7
2018-11-30 17:29:31 -08:00