Skip to content

Commit

Permalink
Adapt ReadableMapBuffer to MapBuffer interface
Browse files Browse the repository at this point in the history
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
  • Loading branch information
Andrei Shikov authored and facebook-github-bot committed Mar 31, 2022
1 parent cf6f3b6 commit 81e4249
Show file tree
Hide file tree
Showing 14 changed files with 460 additions and 589 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/*
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/

package com.facebook.react.common.mapbuffer

import com.facebook.react.bridge.ReactMarker
import com.facebook.react.bridge.ReactMarkerConstants
import com.facebook.soloader.SoLoader
import com.facebook.systrace.Systrace

object MapBufferSoLoader {
@Volatile private var didInit = false

@JvmStatic
fun staticInit() {
if (didInit) {
return
}
didInit = true

Systrace.beginSection(
Systrace.TRACE_TAG_REACT_JAVA_BRIDGE,
"ReadableMapBufferSoLoader.staticInit::load:mapbufferjni")
ReactMarker.logMarker(ReactMarkerConstants.LOAD_REACT_NATIVE_MAPBUFFER_SO_FILE_START)
SoLoader.loadLibrary("mapbufferjni")
ReactMarker.logMarker(ReactMarkerConstants.LOAD_REACT_NATIVE_MAPBUFFER_SO_FILE_END)
Systrace.endSection(Systrace.TRACE_TAG_REACT_JAVA_BRIDGE)
}
}
Loading

0 comments on commit 81e4249

Please sign in to comment.