Skip to content

Commit

Permalink
Rename C++ part of ReadableMapBuffer to JReadableMapBuffer
Browse files Browse the repository at this point in the history
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
  • Loading branch information
Andrei Shikov authored and facebook-github-bot committed Mar 31, 2022
1 parent 81e4249 commit 2a6a685
Show file tree
Hide file tree
Showing 11 changed files with 71 additions and 80 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
/*
* 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.
*/

#include "JReadableMapBuffer.h"

namespace facebook {
namespace react {

void JReadableMapBuffer::registerNatives() {
registerHybrid({
makeNativeMethod(
"importByteBuffer", JReadableMapBuffer::importByteBuffer),
});
}

jni::local_ref<jni::JByteBuffer> JReadableMapBuffer::importByteBuffer() {
// TODO T83483191: Reevaluate what's the best approach here (allocateDirect vs
// DirectByteBuffer).
return jni::JByteBuffer::wrapBytes(
serializedData_.data(), serializedData_.size());
}

std::vector<uint8_t> JReadableMapBuffer::data() const {
return serializedData_;
}

jni::local_ref<JReadableMapBuffer::jhybridobject>
JReadableMapBuffer::createWithContents(MapBuffer &&map) {
return newObjectCxxArgs(std::move(map));
}

JReadableMapBuffer::JReadableMapBuffer(MapBuffer &&map)
: serializedData_(std::move(map.bytes_)) {
react_native_assert(
(serializedData_.size() != 0) && "Error no content in map");
}

} // namespace react
} // namespace facebook
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,17 @@
namespace facebook {
namespace react {

class ReadableMapBuffer : public jni::HybridClass<ReadableMapBuffer> {
class JReadableMapBuffer : public jni::HybridClass<JReadableMapBuffer> {
public:
static auto constexpr kJavaDescriptor =
"Lcom/facebook/react/common/mapbuffer/ReadableMapBuffer;";

static void registerNatives();

static jni::local_ref<ReadableMapBuffer::jhybridobject> createWithContents(
static jni::local_ref<JReadableMapBuffer::jhybridobject> createWithContents(
MapBuffer &&map);

explicit ReadableMapBuffer(MapBuffer &&map);
explicit JReadableMapBuffer(MapBuffer &&map);

jni::local_ref<jni::JByteBuffer> importByteBuffer();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ MapBuffer JWritableMapBuffer::getMapBuffer() {
static const auto integerClass = jni::JInteger::javaClassStatic();
static const auto doubleClass = jni::JDouble::javaClassStatic();
static const auto stringClass = jni::JString::javaClassStatic();
static const auto readableMapClass = ReadableMapBuffer::javaClassStatic();
static const auto readableMapClass = JReadableMapBuffer::javaClassStatic();
static const auto writableMapClass = JWritableMapBuffer::javaClassStatic();

if (value->isInstanceOf(booleanClass)) {
Expand All @@ -50,7 +50,7 @@ MapBuffer JWritableMapBuffer::getMapBuffer() {
builder.putString(key, element->toStdString());
} else if (value->isInstanceOf(readableMapClass)) {
auto element =
jni::static_ref_cast<ReadableMapBuffer::jhybridobject>(value);
jni::static_ref_cast<JReadableMapBuffer::jhybridobject>(value);
builder.putMapBuffer(key, MapBuffer(element->cthis()->data()));
} else if (value->isInstanceOf(writableMapClass)) {
auto element =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
#pragma once

#include <fbjni/fbjni.h>
#include <react/common/mapbuffer/ReadableMapBuffer.h>
#include <react/common/mapbuffer/JReadableMapBuffer.h>

namespace facebook::react {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@

#include <fbjni/fbjni.h>

#include "JReadableMapBuffer.h"
#include "JWritableMapBuffer.h"
#include "ReadableMapBuffer.h"

JNIEXPORT jint JNICALL JNI_OnLoad(JavaVM *vm, void *) {
return facebook::jni::initialize(
vm, [] { facebook::react::ReadableMapBuffer::registerNatives(); });
vm, [] { facebook::react::JReadableMapBuffer::registerNatives(); });
}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,7 @@ local_ref<jobject> FabricMountingManager::getProps(
? static_cast<ViewProps const &>(*oldShadowView.props)
: ViewProps{};
auto newProps = static_cast<ViewProps const &>(*newShadowView.props);
return ReadableMapBuffer::createWithContents(
return JReadableMapBuffer::createWithContents(
viewPropsDiff(oldProps, newProps));
} else {
return ReadableNativeMap::newObjectCxxArgs(newShadowView.props->rawProps);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,12 @@ StateWrapperImpl::getStateDataImpl() {
return readableNativeMap;
}

jni::local_ref<ReadableMapBuffer::jhybridobject>
jni::local_ref<JReadableMapBuffer::jhybridobject>
StateWrapperImpl::getStateMapBufferDataImpl() {
MapBuffer map = state_->getMapBuffer();
auto ReadableMapBuffer =
ReadableMapBuffer::createWithContents(std::move(map));
return ReadableMapBuffer;
auto readableMapBuffer =
JReadableMapBuffer::createWithContents(std::move(map));
return readableMapBuffer;
}

void StateWrapperImpl::updateStateImpl(NativeMap *map) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
#pragma once

#include <fbjni/fbjni.h>
#include <react/common/mapbuffer/ReadableMapBuffer.h>
#include <react/common/mapbuffer/JReadableMapBuffer.h>
#include <react/jni/ReadableNativeMap.h>
#include <react/renderer/core/State.h>

Expand All @@ -26,7 +26,7 @@ class StateWrapperImpl : public jni::HybridClass<StateWrapperImpl> {

static void registerNatives();

jni::local_ref<ReadableMapBuffer::jhybridobject> getStateMapBufferDataImpl();
jni::local_ref<JReadableMapBuffer::jhybridobject> getStateMapBufferDataImpl();
jni::local_ref<ReadableNativeMap::jhybridobject> getStateDataImpl();
void updateStateImpl(NativeMap *map);

Expand Down
6 changes: 3 additions & 3 deletions ReactCommon/react/renderer/mapbuffer/MapBuffer.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
namespace facebook {
namespace react {

class ReadableMapBuffer;
class JReadableMapBuffer;

// clang-format off

Expand Down Expand Up @@ -96,7 +96,7 @@ class MapBuffer {

/**
* Data types available for serialization in MapBuffer
* Keep in sync with `DataType` enum in `ReadableMapBuffer.java`, which
* Keep in sync with `DataType` enum in `JReadableMapBuffer.java`, which
* expects the same values after reading them through JNI.
*/
enum DataType : uint16_t {
Expand Down Expand Up @@ -144,7 +144,7 @@ class MapBuffer {

int32_t getKeyBucket(MapBuffer::Key key) const;

friend ReadableMapBuffer;
friend JReadableMapBuffer;
};

} // namespace react
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

#include <limits>

#include <react/common/mapbuffer/ReadableMapBuffer.h>
#include <react/common/mapbuffer/JReadableMapBuffer.h>
#include <react/jni/ReadableNativeMap.h>
#include <react/renderer/attributedstring/conversions.h>
#include <react/renderer/core/conversions.h>
Expand Down Expand Up @@ -111,18 +111,18 @@ Size measureAndroidComponentMapBuffer(
->getMethod<jlong(
jint,
jstring,
ReadableMapBuffer::javaobject,
ReadableMapBuffer::javaobject,
ReadableMapBuffer::javaobject,
JReadableMapBuffer::javaobject,
JReadableMapBuffer::javaobject,
JReadableMapBuffer::javaobject,
jfloat,
jfloat,
jfloat,
jfloat,
jfloatArray)>("measureMapBuffer");

auto localDataMap =
ReadableMapBuffer::createWithContents(std::move(localData));
auto propsMap = ReadableMapBuffer::createWithContents(std::move(props));
JReadableMapBuffer::createWithContents(std::move(localData));
auto propsMap = JReadableMapBuffer::createWithContents(std::move(props));

auto size = yogaMeassureToSize(measure(
fabricUIManager,
Expand Down Expand Up @@ -287,15 +287,15 @@ LinesMeasurements TextLayoutManager::measureLinesMapBuffer(
static auto measureLines =
jni::findClassStatic("com/facebook/react/fabric/FabricUIManager")
->getMethod<NativeArray::javaobject(
ReadableMapBuffer::javaobject,
ReadableMapBuffer::javaobject,
JReadableMapBuffer::javaobject,
JReadableMapBuffer::javaobject,
jfloat,
jfloat)>("measureLinesMapBuffer");

auto attributedStringMB =
ReadableMapBuffer::createWithContents(toMapBuffer(attributedString));
JReadableMapBuffer::createWithContents(toMapBuffer(attributedString));
auto paragraphAttributesMB =
ReadableMapBuffer::createWithContents(toMapBuffer(paragraphAttributes));
JReadableMapBuffer::createWithContents(toMapBuffer(paragraphAttributes));

auto array = measureLines(
fabricUIManager,
Expand Down

0 comments on commit 2a6a685

Please sign in to comment.