Commit Graph

55 Commits

Author SHA1 Message Date
Chris Olszewski daa105aba5 Fixup typo in pfh labels
Summary:
Now that the PFH node has been renamed this updates the pfh label.

Produced via `xbgs -l -e '"pfh:ReactNative_CommonInfrastructurePlaceholde"' | xargs sed -i 's/"pfh:ReactNative_CommonInfrastructurePlaceholde"/"pfh:ReactNative_CommonInfrastructurePlaceholder"/'`

Reviewed By: jkeljo

Differential Revision: D35374087

fbshipit-source-id: 61590f69de5a69ec3b8a0478f6dd43409de3c70b
2022-04-05 12:15:05 -07:00
Andrei Shikov 2a6a6851ec Rename C++ part of ReadableMapBuffer to JReadableMapBuffer
Summary:
Aligns naming with `JWritableMapBuffer` and other fbjni classes to indicate that it is a JNI binding.

Changelog: [Internal] - Rename C++ part of ReadableMapBuffer to JReadableMapBuffer

Reviewed By: mdvacca

Differential Revision: D35219323

fbshipit-source-id: a7eb644a700a35dc94fa18e4fb3cc68f2cfa3e99
2022-03-30 20:27:23 -07:00
Andrei Shikov cf6f3b680b MapBuffer interface and JVM -> C++ conversion
Summary:
Creates a `WritableMapBuffer` abstraction to pass data from JVM to C++, similarly to `ReadableMapBuffer`. This part also defines a Kotlin interface for both `Readable/WritableMapBuffer` to allow to use them interchangeably on Java side.

`WritableMapBuffer` is using Android's `SparseArray` which has almost identical structure to `MapBuffer`, with `log(N)` random access and instant sequential access.

To avoid paying the cost of JNI transfer, the data is only transferred when requested by native `JWritableMapBuffer::getMapBuffer`. `WritableMapBuffer` also owns it data, meaning it cannot be "consumed" as `WritableNativeMap`, with C++ usually receiving copy of the data on conversion. This allows to use `WritableMapBuffer` as JVM-only implementation of `MapBuffer` interface as well, e.g. for testing (although Robolectric will still be required due to `SparseArray` used as storage)

Changelog: [Android][Added] - MapBuffer implementation for JVM -> C++ communication

Reviewed By: mdvacca

Differential Revision: D35014011

fbshipit-source-id: 8430212bf6152b966cde8e6f483b4f2dab369e4e
2022-03-30 20:27:23 -07:00
Chris Olszewski ceae48c0f7 Add pfh labels to targets
Summary:
While it would be better to be able to do all of the ownership metadata at the Buck macro level, that proved to be more work than expected.

This diff adds the corresponding pfh label to all targets in `xplat/js/react-native-github` that have a Supermodule label. Once the migration is complete the Supermodules labels will be able to be removed.

Reviewed By: cortinico

Differential Revision: D35221544

fbshipit-source-id: d87d5e266dfb5e6ee087251dc34dff5db299bbaf
2022-03-30 14:37:03 -07:00
Chris Olszewski 75edd288cb Backout feature args
Reviewed By: jkeljo

Differential Revision: D35203884

fbshipit-source-id: 87d50b138aaa3dd16a24b5ff2795910c3644d418
2022-03-30 06:53:44 -07:00
CodemodService Bot 590ffad018 Annotate targets with feature xplat/js/react-native-github/ReactCommon/react/renderer/mapbuffer/BUCK -> xplat/js/tools/metro/packages/metro-runtime/src/polyfills/BUCK
Reviewed By: jkeljo

Differential Revision: D35178571

fbshipit-source-id: b8b6fcd49459e37152c02db8c7a6cfed167248a9
2022-03-28 13:22:38 -07:00
Nicola Corti e12bc9cf62 Setup Globbing with CONFIGURE_DEPENDS inside CMake files.
Summary:
This Diff moves from specifying a list of files to use file(GLOB) with
CONFIGURE_DEPENDS on several CMakefiles.
I've updates those where we use globbing also inside buck.

Changelog:
[Internal] [Changed] - Setup Globbing with CONFIGURE_DEPENDS inside CMake files

Reviewed By: ShikaSD

Differential Revision: D34826311

fbshipit-source-id: 8fc654626c897cdc4cdd79c699ce19f1e5e1212f
2022-03-15 01:55:27 -07:00
Nicola Corti b676ca560d First Round of CMake files for React Android
Summary:
This is the first round of CMake files to support the React Native build on Android.
They're supposed to eventually replace the various Android.mk files we have around in the codebase.

So far we're not actively using them. This is the first step towards migrating our
setup to use CMake

Changelog:
[Internal] [Changed] - First Round of CMake files for React Android

Reviewed By: ShikaSD

Differential Revision: D34762524

fbshipit-source-id: 6671e203a2c83b8874cefe796aa55aa987902a3b
2022-03-11 11:39:23 -08:00
Chiara Mooney 42b391775f Fix ReactCommon Break for Windows (#33047)
Summary:
Changes to MapBuffer code in https://github.com/facebook/react-native/compare/aaff15c...d287598 broke build for Windows. Errors included incompatible type conversions, the use of `__attribute__(__packed__)` which is only supported by GCC and Clang, and the usage of designated initializers which are only supported on C++20.

Changes here restore build on Windows.

## Changelog

<!-- Help reviewers and the release process by writing your own changelog entry. For an example, see:
https://github.com/facebook/react-native/wiki/Changelog
-->

[General] [Fixed] - Fix build break on Windows with ReactCommon

Pull Request resolved: https://github.com/facebook/react-native/pull/33047

Test Plan: React Native project built on Windows and passes react-native-windows repository pipeline. These edits are currently merged into the main branch of react-native-windows.

Reviewed By: ShikaSD

Differential Revision: D34101367

Pulled By: philIip

fbshipit-source-id: 1596365c2e92f377c6375805b33de5e1c7b78e66
2022-02-09 13:03:10 -08:00
Andrei Shikov 3c86e82a02 Namespace MapBuffer structs and typealiases by moving them into class
Summary:
Refactors MapBuffer-related `primitives.h` to be namespaced with `MapBuffer` class, to avoid name collisions and confusion later on.
Most of the size constants are moved to relevant .cpp files or updated to use `sizeof`.

Additionally, adds a little bit of documentation about `MapBuffer` serialization format.

Changelog: [Internal]

Reviewed By: mdvacca

Differential Revision: D33662487

fbshipit-source-id: 5a7a2b1c7f2bb13ee1edfc5fae51ba88c34f0d3c
2022-01-20 12:57:22 -08:00
Andrei Shikov adb2167640 Serialize and assert type information in mapbuffer
Summary:
Serializes type information along with key/value in MapBuffer, asserting the data type on Java side during read. At the moment, accessing value with incorrect will result in a crash.

Other changes:
Adds a `getType` method to verify types before accessing them.
Removes `null` as a type, as just not inserting value and checking for its existence with `hasKey` is more optimal.

Changelog: [Internal]

Reviewed By: mdvacca

Differential Revision: D33656841

fbshipit-source-id: 23a78daa0d84704aab141088b5dfe881e9609472
2022-01-20 12:57:22 -08:00
Andrei Shikov d287598d23 Allow random stores and accesses to MapBuffer values
Summary:
Removes the need to store keys in incremental order by sorting them after before inserting into MapBuffer.
Updates MapBuffer to support random access on C++ side, actually retrieving values by keys and not bucket index.

Changelog: [Internal]

Reviewed By: mdvacca

Differential Revision: D33611758

fbshipit-source-id: c81e970613c8ecc688bfacb29ba038bf081a0c0f
2022-01-20 12:57:22 -08:00
Andrei Shikov b173bf3c0e Minor MapBuffer renames for consistency
Summary:
Rename `_header` to `header_` to align with the C++ naming scheme we use.
Rename `readKey` to `readUnsignedShort` as purpose of the method have changed.

Changelog: [Internal]

Reviewed By: javache

Differential Revision: D33637127

fbshipit-source-id: a82f4d6c1b753b21e0567fbe919af98e4c78105d
2022-01-18 18:00:07 -08:00
Andrei Shikov c338fff521 Cast MapBuffer bytes to struct to read header
Summary:
The struct is copied directly to the buffer, so it is safe to read it back.

Changelog: [Internal]

Reviewed By: javache

Differential Revision: D33624036

fbshipit-source-id: 7ee2b28b815690ab471832c0c622a075b5dd7d78
2022-01-18 08:04:54 -08:00
Andrei Shikov 5b489d5f95 Use vector for dynamic data in MapBufferBuilder
Summary:
Replaces dynamic manually managed array with a vector of bytes, removing the need for managing memory manually.

This approach is a little bit slower than before, as vector is allocating memory more conservatively. This can be improved in the future by providing an estimate for the data size.

Changelog: [Internal]

Reviewed By: javache

Differential Revision: D33611759

fbshipit-source-id: a0e5e57c4e413206a9f891cd5630ecc9088a9bf7
2022-01-17 13:15:49 -08:00
Andrei Shikov b1ef4405ee Use struct for building mapbuffer buckets
Summary:
Instead of copying integer values into key/value data array, this implementation keeps a structured vector of `Bucket` structs (which is sized to be serialized later).

This approach provides multiple benefits to modify and access buckets (e.g. sort them based on the key, allowing for out of order inserts (D33611758))

Changelog: [Internal]

Reviewed By: javache

Differential Revision: D33601231

fbshipit-source-id: 62ace1374936cb504836d6eae672e909ea404e3f
2022-01-17 13:15:49 -08:00
Andrei Shikov 0b48ef7ca8 Add more complex perf test for the mapbuffer
Summary:
Benchmarks performance/correctness of mapbuffer with several different types of data

Changelog: [Internal]

Reviewed By: mdvacca

Differential Revision: D33608299

fbshipit-source-id: 81b1e195aecac60ad1cc3ca416d1cf7b09feab32
2022-01-16 23:07:40 -08:00
Andrei Shikov ea712f825a Use reference when copying strings into mapbuffer
Summary:
This method can produce unnecessary copy of the string, replacing it with reference to optimize.

Changelog: [Internal]

Reviewed By: mdvacca

Differential Revision: D33607765

fbshipit-source-id: e04eddffec063c0c8e173bfdf690e7b8e1050525
2022-01-16 23:07:40 -08:00
Andrei Shikov f33892081a Cleanup ReadableMapBuffer
Summary:
Cleans up `ReadableMapBuffer` APIs and migrates to use `std::vector` instead of raw pointer array.

Also uses `fbjni` utility to allocate the bytes instead of making manual JNI calls.

Changelog: [Internal]

Reviewed By: sammy-SC

Differential Revision: D33513027

fbshipit-source-id: afe7d320d12830503de4c9994117d849f0b25245
2022-01-12 08:13:32 -08:00
Andrei Shikov aaff15c2c8 Use std::vector to manage MapBuffer storage
Summary:
Replaces raw array pointer inside `MapBuffer` with `std::vector`, which is more conventional "safer" way of storing dynamically sized arrays.

Changelog: [Internal]

Reviewed By: mdvacca

Differential Revision: D33512115

fbshipit-source-id: d875a2240f7938fd35c4c3ae0e7e91dc7456ff32
2022-01-12 08:13:32 -08:00
Andres Suarez 8bd3edec88 Update copyright headers from Facebook to Meta
Reviewed By: aaronabramov

Differential Revision: D33367752

fbshipit-source-id: 4ce94d184485e5ee0a62cf67ad2d3ba16e285c8f
2021-12-30 15:11:21 -08:00
Nicola Corti b8f415eb6c Update LOCAL_SHARED_LIBRARIES to be a multiline string
Summary:
We have `LOCAL_SHARED_LIBRARIES` that are getting longer and are
making reviewing them on Diffs quite hard.
Having all the list of the dependency on a single line is suboptimal
and it makes hard to find duplicated entries.
I've updated the longest `LOCAL_SHARED_LIBRARIES` to be multilines and
I've sorted the entries here.

Changelog:
[Internal] [Changed] - LOCAL_SHARED_LIBRARIES

Reviewed By: ShikaSD

Differential Revision: D32695127

fbshipit-source-id: f5b381c501ddff083ef9f4baaca6c4c8c9523368
2021-11-29 13:01:51 -08:00
Joshua Gross b60e229d7f Remove compiler_flags from BUCK modules
Summary:
Nearly all of these are identical and these compiler_flags are now centralized in rn_defs.bzl. This should have NO CHANGE on build configuration, the flags have just moved for now.

Changelog: [Internal]

Reviewed By: mdvacca

Differential Revision: D31631766

fbshipit-source-id: be40ebeb70ae52b7ded07ca08c4a29f10a0ed925
2021-10-14 15:34:29 -07:00
Chatura Atapattu 2c2b831716 Apply new buildifier fixes
Summary: Changelog: [Internal]

Reviewed By: zertosh

Differential Revision: D30407205

fbshipit-source-id: 022a02829d59a900764b228afb9856ed1ba2cf8c
2021-08-19 20:01:02 -07:00
Igor Klemenski 6d04a46f74 Add explicit type casts to fix compilation errors on Windows. (#31363)
Summary:
Recent changes to `MapBuffer` have broken the compilation on Windows.
This fix is similar to this recently-merged change: https://github.com/facebook/react-native/pull/31106

Side note - this PR only addresses a build break, but doesn't address the unsafe casting semantics in `MapBuffer`, which can still cause overflows.

## Changelog

<!-- Help reviewers and the release process by writing your own changelog entry. For an example, see:
https://github.com/facebook/react-native/wiki/Changelog
-->

[General] [Fixed] - Fix compilation errors on Windows.

Pull Request resolved: https://github.com/facebook/react-native/pull/31363

Test Plan: RN now builds in Visual Studio on Windows.

Reviewed By: mdvacca

Differential Revision: D28028342

Pulled By: rozele

fbshipit-source-id: 77d8d4870c59b77acfc0ab2f4c3b7df40b59851d
2021-05-03 09:35:28 -07:00
David Vacca b67dc01d1d Replace int -> int32_t
Summary:
This diff replaces all usages of int by int32_t. This is to ensure we always use a fixed size for int that matches what's expected on Java.

changelog: [internal] internal

Reviewed By: sammy-SC

Differential Revision: D27915608

fbshipit-source-id: 634c45796dda1d4434c3ad6ff3e199931c22940b
2021-04-22 09:50:23 -07:00
David Vacca 091197be5e Fix MapBufferBuilder::ensureDynamicDataSpace
Summary:
There was a subtle bug in MapBufferBuilder::ensureDynamicDataSpace where in some situations allowed MapBufferBuilder to use unowned memory.

changelog: [internal] internal

Reviewed By: JoshuaGross

Differential Revision: D27904642

fbshipit-source-id: de447633349094b0e8c5cb5e377dd31f5bfd1471
2021-04-21 10:27:57 -07:00
David Vacca b614afc613 Refactor MapBufferBuilder to use int to store size of Mapbuffer data
Summary:
Refactor MapBufferBuilder to use int to store size of Mapbuffer data

changelog: [internal] internal

Reviewed By: JoshuaGross

Differential Revision: D27904646

fbshipit-source-id: 6b8b96fdd30184b6d35c1d612743eae653854d6d
2021-04-21 10:27:57 -07:00
David Vacca 668d71aa0b Refactor dataSize to use int instead of short
Summary:
DynamicData can contain a big amount of data, refactoring type to use int instead of short

changelog: [internal] internal

Reviewed By: sammy-SC

Differential Revision: D27904643

fbshipit-source-id: 157064b280e27a9c7c4a4f55af310392b178feda
2021-04-21 10:27:57 -07:00
David Vacca f946001c4e Change type of MapBufferBuilder.dynamicDataSize variable
Summary:
Dynamicdata can contain long datastructures, increasing type of MapBufferBuilder.dynamicDataSize to int

changelog: [internal] internal

Reviewed By: sammy-SC

Differential Revision: D27904647

fbshipit-source-id: ccbccf9328a6aa301aa3f9bf5c1b3c20f56e2a19
2021-04-21 10:27:57 -07:00
David Vacca 8cdba40987 Fix MapBuffer.getString() method
Summary:
found a bug in MapBuffer.getString() method, this diff is fixing it

changelog: [internal] internal

Reviewed By: sammy-SC

Differential Revision: D27904644

fbshipit-source-id: 746812235539ff75c5ce53c6f872ede9779fa1fa
2021-04-21 10:27:57 -07:00
David Vacca c9a69de962 Add TODOs and Tasks into TODOs
Summary:
Add TODOs and Tasks into TODOs

changelog: [internal] internal

Reviewed By: sammy-SC

Differential Revision: D27865470

fbshipit-source-id: fcc7f86b0e6b290bf9f691a2dafea18d8addf782
2021-04-20 12:13:48 -07:00
David Vacca a32a636909 Fix assert in mapbufferBuilder
Summary:
This diff fixes an assert in mapbufferBuilder

changelog: [internal] internal

Reviewed By: sammy-SC

Differential Revision: D27864306

fbshipit-source-id: fbeb812906441c50bf51ca71566fcd6f6e494322
2021-04-20 12:13:48 -07:00
David Vacca 0bb05789b2 Add assert in constructor of MapBuffer
Summary:
This diff adds an assert in the constructor of MapBuffer to ensure that we always access valid memory

changelog: [internal] internal

Reviewed By: sammy-SC

Differential Revision: D27864310

fbshipit-source-id: bd3870b6df1dbc5181fc5d852eb0ccbc32a8a951
2021-04-20 12:13:48 -07:00
David Vacca 7d326a98f6 Refactor MapBuffer::getCount
Summary:
EZ refactor of MapBuffer::getCount and removal of TODO

changelog: [internal] internal

Reviewed By: sammy-SC

Differential Revision: D27864307

fbshipit-source-id: 14138090b3f2b45de8e0a3941abec990edb427ed
2021-04-20 12:13:48 -07:00
David Vacca e2b9c61998 Add assertion when building MapBuffer
Summary:
This diff adds an assertion when trying to build a MapBuffer with invalid data

changelog: [internal] internal

Reviewed By: sammy-SC

Differential Revision: D27864309

fbshipit-source-id: 6601388e56be18ded0675f92cce009a577828c16
2021-04-20 12:13:47 -07:00
David Vacca 4d9973fa59 Use explicit initial values for internal data of MapBufferBuilder
Summary:
Use explicit initial values for internal data of MapBufferBuilder

changelog: [internal] internal

Reviewed By: sammy-SC

Differential Revision: D27864311

fbshipit-source-id: 1e861d90da5ba52dfe560630b50aa4e1e741f66c
2021-04-20 12:13:47 -07:00
David Vacca 8b5ad95a30 Use explicit initial values for internal data of MapBuffer
Summary:
Use explicit initial values for internal data of MapBuffer

changelog: [internal] internal

Reviewed By: sammy-SC

Differential Revision: D27864308

fbshipit-source-id: f90fb34735ba190b9ca96da245f3c478640eb537
2021-04-20 12:13:47 -07:00
David Vacca aee07e1203 Integrate react_native_asserts into mapbuffer
Summary:
Integrate react_native_asserts into mapbuffer

changelog: [internal] internal

Reviewed By: JoshuaGross

Differential Revision: D27753092

fbshipit-source-id: dbeb7f140f3096c8153e2f6bced4e4d9d88b48b8
2021-04-13 21:32:17 -07:00
Samuel Susla 9ef995a14a Enable C++ 17 in React Native
Summary:
Changelog: [Internal] enable support for C++ 17.

C++ 17 in React Native targets.

Short and comprehensive list of C++ features:
https://github.com/AnthonyCalandra/modern-cpp-features#c17-language-features

Reviewed By: JoshuaGross

Differential Revision: D27431145

fbshipit-source-id: e8da6fe9d70e9b7343a8caec21cdbeb043478575
2021-04-01 04:50:59 -07:00
David Vacca 3bbb0a43c2 Remove exceptions from MapBufferBuilder class
Summary:
In Fabric we don't throw exception. This diff removes exception from MapBufferBuilder class

changelog: [internal] internal

Reviewed By: JoshuaGross, sammy-SC

Differential Revision: D27303493

fbshipit-source-id: 8303bb4be786e2ea175b6741ec536c0f54615001
2021-03-24 17:20:11 -07:00
David Vacca 0b5fbf367d Remove exceptions from MapBuffer class
Summary:
In Fabric we don't throw exception. This diff removes exception from MapBuffer class

changelog: [internal] internal

Reviewed By: JoshuaGross, sammy-SC

Differential Revision: D27303496

fbshipit-source-id: 3f8c3bd2b41121672ef05153459b20cdc2efcda3
2021-03-24 17:20:11 -07:00
David Vacca 7704f651a0 change class variable syntax in MapBufferBuilder class
Summary:
This diff changes the syntax of class variables in MapBufferBuilder class to make it consistent with standards

changelog: [internal] internal

Reviewed By: JoshuaGross

Differential Revision: D27303495

fbshipit-source-id: b62067a07c5b2df1ae79b0134343d30ec819a55f
2021-03-24 17:20:11 -07:00
David Vacca 0599de5768 change class variable syntax in MapBuffer class
Summary:
This diff changes the syntax of class variables in MapBuffer class to make it consistent with standards

changelog: [internal] internal

Reviewed By: JoshuaGross, sammy-SC

Differential Revision: D27303497

fbshipit-source-id: 7581ce248559726c301ae96312fcb597a061ad5f
2021-03-24 17:20:11 -07:00
David Vacca 91b3f5d48a Implement and integrate Mapbuffer
Summary:
This diff contains the code from the 35 diff stack  - D27210587

This diff implement and integrates Mapbuffer into Fabric text measure system

changelog: [internal] internal

Reviewed By: JoshuaGross

Differential Revision: D27241836

fbshipit-source-id: f40a780df0723f27da440f709a8676cfcca63953
2021-03-24 03:52:31 -07:00
David Vacca 866bf5f424 Primitive.h -> primitives.h
Summary:
Refactor Primitives.h -> primitives.h

changelog: [internal] internal

Reviewed By: JoshuaGross

Differential Revision: D27210461

fbshipit-source-id: 6b540e20c9123df6b10909564530acfe10845082
2021-03-22 09:16:57 -07:00
David Vacca f3fc425ce4 Primitives.h -> Primitive.h
Summary:
Refactor Primitives.h -> Primitive.h

changelog: [internal] internal

Reviewed By: JoshuaGross

Differential Revision: D26498384

fbshipit-source-id: 5140a88aa6ced3dff5b0e08082e580588ae5ba02
2021-03-22 09:16:57 -07:00
Igor Klemenski e69f1c9f50 Fix unsafe cast and detect resize overflow. (#31106)
Summary:
Removing unsafe cast from `int` to `uint16_t`.
Also, adding code to detect multiplication overflow during buffer resize.

## Changelog

<!-- Help reviewers and the release process by writing your own changelog entry. For an example, see:
https://github.com/facebook/react-native/wiki/Changelog
-->

[General] [Fix] - Fix unsafe cast and detect overflow in MapBuffer.

Pull Request resolved: https://github.com/facebook/react-native/pull/31106

Test Plan: Code compiles in Visual Studio 2019 without the unsafe cast warning (or error depending on the configuration).

Reviewed By: mdvacca

Differential Revision: D26865138

Pulled By: rozele

fbshipit-source-id: 4692a38b05fc873e31fbbe94d70803244e82de5d
2021-03-09 08:47:31 -08:00
Joshua Gross 88088b7851 ReactCommon/renderer/mapbuffer: Migrate uses of NDEBUG to REACT_NATIVE_DEBUG + react_native_assert
Summary:
For better cross-platform consistency, migrate usages of NDEBUG to REACT_NATIVE_DEBUG. See flags.h for explanation.

Changelog: [Internal]

Reviewed By: PeteTheHeat

Differential Revision: D26695224

fbshipit-source-id: 3044049cb2447a733a9ecae84dcc099b26731acd
2021-02-26 23:30:00 -08:00
David Vacca 528d51e583 MapBuffer C++ unit tests
Summary:
Unit tests for MapBuffer

changelog: [internal] internal

Reviewed By: sammy-SC

Differential Revision: D26364356

fbshipit-source-id: a4b08c978c05e6b709329d553e0c44ede1a92cbf
2021-02-17 15:47:08 -08:00