Adapt ReadableMapBuffer to MapBuffer interface

Summary:
Updates `ReadableMapBuffer` to conform to `MapBuffer` interface, to allow interchangeable use of `Readable/WritableMapBuffer` in the code.

Notable changes:
- MapBuffer.Entry getters are now represented as Kotlin properties and appended `Value` suffix (e.g. `entry.getInt()` becomes `entry.getIntValue()` in Java, or `entry.intValue` in Kotlin)
- `ByteBuffer` is imported in constructor instead of on demand. This method doesn't copy the data as the bytes are read directly from native heap, and benchmarking a 500-byte `MapBuffer` shows no difference in import speed.
- Internal logic of `ReadableMapBuffer` uses `UShort` kotlin type for key retrieval, for more correct representation of values.
- Explicit exception throws are replaced with `require` and `check` methods for `IllegalArgumentException` and `IllegalStateException` (default FB conversion).

The change also updates `ReadableMapBuffer` usages to `MapBuffer` interface where possible (virtually everywhere except JNI methods).

Changelog: [Android][Changed] - Adopt `MapBuffer` interface for `ReadableMapBuffer`

Reviewed By: mdvacca

Differential Revision: D35218633

fbshipit-source-id: 515dd974c27b2978ade325b2e1750ab8f068a20a
This commit is contained in:
Andrei Shikov
2022-03-30 20:27:23 -07:00
committed by Facebook GitHub Bot
parent cf6f3b680b
commit 81e4249315
14 changed files with 460 additions and 589 deletions
@@ -14,6 +14,7 @@ rn_android_library(
"pfh:ReactNative_CommonInfrastructurePlaceholde",
"supermodule:xplat/default/public.react_native.infra",
],
language = "KOTLIN",
provided_deps = [
react_native_dep("third-party/android/androidx:annotation"),
react_native_dep("third-party/android/androidx:core"),
@@ -21,6 +22,7 @@ rn_android_library(
react_native_dep("third-party/android/androidx:legacy-support-core-ui"),
react_native_dep("third-party/android/androidx:legacy-support-core-utils"),
],
pure_kotlin = False,
required_for_source_only_abi = True,
visibility = [
"PUBLIC",
@@ -11,7 +11,7 @@ import androidx.annotation.NonNull;
import com.facebook.react.bridge.JSIModuleProvider;
import com.facebook.react.bridge.ReactApplicationContext;
import com.facebook.react.bridge.UIManager;
import com.facebook.react.common.mapbuffer.ReadableMapBufferSoLoader;
import com.facebook.react.common.mapbuffer.MapBufferSoLoader;
import com.facebook.react.config.ReactFeatureFlags;
import com.facebook.react.fabric.events.EventBeatManager;
import com.facebook.react.uimanager.ViewManagerRegistry;
@@ -46,7 +46,7 @@ public class FabricJSIModuleProvider implements JSIModuleProvider<UIManager> {
final Binding binding = new Binding();
if (ReactFeatureFlags.isMapBufferSerializationEnabled()) {
ReadableMapBufferSoLoader.staticInit();
MapBufferSoLoader.staticInit();
}
binding.register(
@@ -23,7 +23,7 @@ import com.facebook.react.bridge.ReadableArray;
import com.facebook.react.bridge.ReadableMap;
import com.facebook.react.bridge.RetryableMountingLayerException;
import com.facebook.react.bridge.UiThreadUtil;
import com.facebook.react.common.mapbuffer.ReadableMapBuffer;
import com.facebook.react.common.mapbuffer.MapBuffer;
import com.facebook.react.fabric.FabricUIManager;
import com.facebook.react.fabric.events.EventEmitterWrapper;
import com.facebook.react.fabric.mounting.mountitems.MountItem;
@@ -396,9 +396,9 @@ public class MountingManager {
public long measureMapBuffer(
@NonNull ReactContext context,
@NonNull String componentName,
@NonNull ReadableMapBuffer localData,
@NonNull ReadableMapBuffer props,
@Nullable ReadableMapBuffer state,
@NonNull MapBuffer localData,
@NonNull MapBuffer props,
@Nullable MapBuffer state,
float width,
@NonNull YogaMeasureMode widthMode,
float height,