Skip to content

Commit 81e4249

Browse files
Andrei Shikovfacebook-github-bot
Andrei Shikov
authored andcommitted
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
1 parent cf6f3b6 commit 81e4249

14 files changed

+460
-589
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
/*
2+
* Copyright (c) Meta Platforms, Inc. and affiliates.
3+
*
4+
* This source code is licensed under the MIT license found in the
5+
* LICENSE file in the root directory of this source tree.
6+
*/
7+
8+
package com.facebook.react.common.mapbuffer
9+
10+
import com.facebook.react.bridge.ReactMarker
11+
import com.facebook.react.bridge.ReactMarkerConstants
12+
import com.facebook.soloader.SoLoader
13+
import com.facebook.systrace.Systrace
14+
15+
object MapBufferSoLoader {
16+
@Volatile private var didInit = false
17+
18+
@JvmStatic
19+
fun staticInit() {
20+
if (didInit) {
21+
return
22+
}
23+
didInit = true
24+
25+
Systrace.beginSection(
26+
Systrace.TRACE_TAG_REACT_JAVA_BRIDGE,
27+
"ReadableMapBufferSoLoader.staticInit::load:mapbufferjni")
28+
ReactMarker.logMarker(ReactMarkerConstants.LOAD_REACT_NATIVE_MAPBUFFER_SO_FILE_START)
29+
SoLoader.loadLibrary("mapbufferjni")
30+
ReactMarker.logMarker(ReactMarkerConstants.LOAD_REACT_NATIVE_MAPBUFFER_SO_FILE_END)
31+
Systrace.endSection(Systrace.TRACE_TAG_REACT_JAVA_BRIDGE)
32+
}
33+
}

0 commit comments

Comments
 (0)