react-native-windows 0.68.0-preview.6 → 0.68.0-preview.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.flowconfig +2 -0
- package/Libraries/Core/ReactNativeVersion.js +1 -1
- package/Microsoft.ReactNative/Microsoft.ReactNative.vcxproj +8 -9
- package/PropertySheets/Generated/PackageVersion.g.props +1 -1
- package/package.json +6 -5
- package/ReactCommon/TEMP_UntilReactCommonUpdate/react/renderer/mapbuffer/MapBuffer.cpp +0 -128
- package/ReactCommon/TEMP_UntilReactCommonUpdate/react/renderer/mapbuffer/MapBuffer.h +0 -150
- package/ReactCommon/TEMP_UntilReactCommonUpdate/react/renderer/mapbuffer/MapBufferBuilder.cpp +0 -149
- package/ReactCommon/TEMP_UntilReactCommonUpdate/react/renderer/mapbuffer/MapBufferBuilder.h +0 -59
- package/ReactCommon/TEMP_UntilReactCommonUpdate/react/renderer/mapbuffer/tests/MapBufferTest.cpp +0 -167
package/.flowconfig
CHANGED
|
@@ -59,6 +59,8 @@
|
|
|
59
59
|
; Ignore the src folder - flow files are combined with ones from react-native into the root Libraries folder
|
|
60
60
|
.*/vnext/src/.*
|
|
61
61
|
|
|
62
|
+
.*/node_modules/resolve/test/resolver/malformed_package_json/package\.json$
|
|
63
|
+
|
|
62
64
|
[untyped]
|
|
63
65
|
.*/node_modules/@react-native-community/cli/.*/.*
|
|
64
66
|
|
|
@@ -24,7 +24,6 @@
|
|
|
24
24
|
<Import Project="$(ReactNativeWindowsDir)PropertySheets\React.Cpp.props" />
|
|
25
25
|
<Import Project="$(ReactNativeWindowsDir)PropertySheets\Generated\PackageVersion.g.props" />
|
|
26
26
|
<Import Project="$(ReactNativeWindowsDir)PropertySheets\PackageVersionDefinitions.props" />
|
|
27
|
-
<Import Project="$(SolutionDir)packages\Microsoft.Web.WebView2.$(WebView2Version)\build\native\Microsoft.Web.WebView2.props" Condition="'$(WebView2Version)'!='' And Exists('$(SolutionDir)packages\Microsoft.Web.WebView2.$(WebView2Version)\build\native\Microsoft.Web.WebView2.props')" />
|
|
28
27
|
<ItemGroup Label="ProjectConfigurations">
|
|
29
28
|
<ProjectConfiguration Include="Debug|ARM64">
|
|
30
29
|
<Configuration>Debug</Configuration>
|
|
@@ -138,7 +137,14 @@
|
|
|
138
137
|
</ClCompile>
|
|
139
138
|
<Link>
|
|
140
139
|
<AdditionalDependencies>winsqlite3.lib;ChakraRT.lib;dxguid.lib;dloadhelper.lib;OneCoreUap_apiset.lib;%(AdditionalDependencies)</AdditionalDependencies>
|
|
141
|
-
<DelayLoadDLLs>
|
|
140
|
+
<DelayLoadDLLs>
|
|
141
|
+
api-ms-win-core-file-l1-2-0.dll;
|
|
142
|
+
api-ms-win-core-windowserrorreporting-l1-1-0.dll;
|
|
143
|
+
ext-ms-win-uiacore-l1-1-1.dll;
|
|
144
|
+
chakra.dll;
|
|
145
|
+
winsqlite3.dll;
|
|
146
|
+
%(DelayLoadDLLs)
|
|
147
|
+
</DelayLoadDLLs>
|
|
142
148
|
<SubSystem>Console</SubSystem>
|
|
143
149
|
<GenerateWindowsMetadata>true</GenerateWindowsMetadata>
|
|
144
150
|
<ModuleDefinitionFile>Microsoft.ReactNative.def</ModuleDefinitionFile>
|
|
@@ -832,13 +838,6 @@
|
|
|
832
838
|
</ItemGroup>
|
|
833
839
|
</When>
|
|
834
840
|
</Choose>
|
|
835
|
-
<Choose>
|
|
836
|
-
<When Condition="'$(WebView2Version)'!=''">
|
|
837
|
-
<ItemGroup>
|
|
838
|
-
<PackageReference Include="Microsoft.Web.WebView2" Version="$(WebView2Version)" />
|
|
839
|
-
</ItemGroup>
|
|
840
|
-
</When>
|
|
841
|
-
</Choose>
|
|
842
841
|
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
|
|
843
842
|
<Import Project="$(ReactNativeWindowsDir)PropertySheets\FastBuild.targets" />
|
|
844
843
|
<Import Project="$(ReactNativeWindowsDir)PropertySheets\FixupRoslynCscWarnings.targets" />
|
|
@@ -10,7 +10,7 @@
|
|
|
10
10
|
-->
|
|
11
11
|
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
|
12
12
|
<PropertyGroup>
|
|
13
|
-
<ReactNativeWindowsVersion>0.68.0-preview.
|
|
13
|
+
<ReactNativeWindowsVersion>0.68.0-preview.7</ReactNativeWindowsVersion>
|
|
14
14
|
<ReactNativeWindowsMajor>0</ReactNativeWindowsMajor>
|
|
15
15
|
<ReactNativeWindowsMinor>68</ReactNativeWindowsMinor>
|
|
16
16
|
<ReactNativeWindowsPatch>0</ReactNativeWindowsPatch>
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "react-native-windows",
|
|
3
|
-
"version": "0.68.0-preview.
|
|
3
|
+
"version": "0.68.0-preview.7",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -23,11 +23,11 @@
|
|
|
23
23
|
"dependencies": {
|
|
24
24
|
"@babel/runtime": "^7.0.0",
|
|
25
25
|
"@jest/create-cache-key-function": "^27.0.1",
|
|
26
|
-
"@react-native-community/cli": "^7.0.
|
|
26
|
+
"@react-native-community/cli": "^7.0.3",
|
|
27
27
|
"@react-native-community/cli-platform-android": "^7.0.1",
|
|
28
28
|
"@react-native-community/cli-platform-ios": "^7.0.1",
|
|
29
29
|
"@react-native-windows/cli": "0.68.0-preview.6",
|
|
30
|
-
"@react-native-windows/virtualized-list": "0.68.0-preview.
|
|
30
|
+
"@react-native-windows/virtualized-list": "0.68.0-preview.3",
|
|
31
31
|
"@react-native/assets": "1.0.0",
|
|
32
32
|
"@react-native/normalize-color": "2.0.0",
|
|
33
33
|
"@react-native/polyfills": "2.0.0",
|
|
@@ -47,6 +47,7 @@
|
|
|
47
47
|
"promise": "^8.0.3",
|
|
48
48
|
"react-devtools-core": "^4.23.0",
|
|
49
49
|
"react-native-codegen": "^0.0.13",
|
|
50
|
+
"react-native-gradle-plugin": "^0.0.5",
|
|
50
51
|
"react-refresh": "^0.4.0",
|
|
51
52
|
"react-shallow-renderer": "16.14.1",
|
|
52
53
|
"regenerator-runtime": "^0.13.2",
|
|
@@ -73,7 +74,7 @@
|
|
|
73
74
|
"metro-config": "^0.67.0",
|
|
74
75
|
"prettier": "^2.4.1",
|
|
75
76
|
"react": "17.0.2",
|
|
76
|
-
"react-native": "0.68.0-rc.
|
|
77
|
+
"react-native": "0.68.0-rc.2",
|
|
77
78
|
"react-native-platform-override": "^1.6.4",
|
|
78
79
|
"react-refresh": "^0.4.0",
|
|
79
80
|
"react-shallow-renderer": "16.14.1",
|
|
@@ -81,7 +82,7 @@
|
|
|
81
82
|
},
|
|
82
83
|
"peerDependencies": {
|
|
83
84
|
"react": "17.0.2",
|
|
84
|
-
"react-native": "0.68.0-rc.
|
|
85
|
+
"react-native": "0.68.0-rc.2"
|
|
85
86
|
},
|
|
86
87
|
"beachball": {
|
|
87
88
|
"defaultNpmTag": "preview",
|
|
@@ -1,128 +0,0 @@
|
|
|
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
|
-
#include "MapBuffer.h"
|
|
9
|
-
|
|
10
|
-
using namespace facebook::react;
|
|
11
|
-
|
|
12
|
-
namespace facebook {
|
|
13
|
-
namespace react {
|
|
14
|
-
|
|
15
|
-
static inline int32_t bucketOffset(int32_t index) {
|
|
16
|
-
return sizeof(MapBuffer::Header) + sizeof(MapBuffer::Bucket) * index;
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
static inline int32_t valueOffset(int32_t bucketIndex) {
|
|
20
|
-
return bucketOffset(bucketIndex) + offsetof(MapBuffer::Bucket, data);
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
// TODO T83483191: Extend MapBuffer C++ implementation to support basic random
|
|
24
|
-
// access
|
|
25
|
-
MapBuffer::MapBuffer(std::vector<uint8_t> data) : bytes_(std::move(data)) {
|
|
26
|
-
auto header = reinterpret_cast<Header const *>(bytes_.data());
|
|
27
|
-
count_ = header->count;
|
|
28
|
-
|
|
29
|
-
if (header->bufferSize != bytes_.size()) {
|
|
30
|
-
LOG(ERROR) << "Error: Data size does not match, expected "
|
|
31
|
-
<< header->bufferSize << " found: " << bytes_.size();
|
|
32
|
-
abort();
|
|
33
|
-
}
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
int32_t MapBuffer::getKeyBucket(Key key) const {
|
|
37
|
-
int32_t lo = 0;
|
|
38
|
-
int32_t hi = count_ - 1;
|
|
39
|
-
while (lo <= hi) {
|
|
40
|
-
int32_t mid = (lo + hi) >> 1;
|
|
41
|
-
|
|
42
|
-
Key midVal =
|
|
43
|
-
*reinterpret_cast<Key const *>(bytes_.data() + bucketOffset(mid));
|
|
44
|
-
|
|
45
|
-
if (midVal < key) {
|
|
46
|
-
lo = mid + 1;
|
|
47
|
-
} else if (midVal > key) {
|
|
48
|
-
hi = mid - 1;
|
|
49
|
-
} else {
|
|
50
|
-
return mid;
|
|
51
|
-
}
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
return -1;
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
int32_t MapBuffer::getInt(Key key) const {
|
|
58
|
-
auto bucketIndex = getKeyBucket(key);
|
|
59
|
-
react_native_assert(bucketIndex != -1 && "Key not found in MapBuffer");
|
|
60
|
-
|
|
61
|
-
return *reinterpret_cast<int32_t const *>(
|
|
62
|
-
bytes_.data() + valueOffset(bucketIndex));
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
bool MapBuffer::getBool(Key key) const {
|
|
66
|
-
return getInt(key) != 0;
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
double MapBuffer::getDouble(Key key) const {
|
|
70
|
-
auto bucketIndex = getKeyBucket(key);
|
|
71
|
-
react_native_assert(bucketIndex != -1 && "Key not found in MapBuffer");
|
|
72
|
-
|
|
73
|
-
return *reinterpret_cast<double const *>(
|
|
74
|
-
bytes_.data() + valueOffset(bucketIndex));
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
int32_t MapBuffer::getDynamicDataOffset() const {
|
|
78
|
-
// The start of dynamic data can be calculated as the offset of the next
|
|
79
|
-
// key in the map
|
|
80
|
-
return bucketOffset(count_);
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
std::string MapBuffer::getString(Key key) const {
|
|
84
|
-
// TODO T83483191:Add checks to verify that offsets are under the boundaries
|
|
85
|
-
// of the map buffer
|
|
86
|
-
int32_t dynamicDataOffset = getDynamicDataOffset();
|
|
87
|
-
int32_t offset = getInt(key);
|
|
88
|
-
int32_t stringLength = *reinterpret_cast<int32_t const *>(
|
|
89
|
-
bytes_.data() + dynamicDataOffset + offset);
|
|
90
|
-
uint8_t const *stringPtr =
|
|
91
|
-
bytes_.data() + dynamicDataOffset + offset + sizeof(int);
|
|
92
|
-
|
|
93
|
-
return std::string(stringPtr, stringPtr + stringLength);
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
MapBuffer MapBuffer::getMapBuffer(Key key) const {
|
|
97
|
-
// TODO T83483191: Add checks to verify that offsets are under the boundaries
|
|
98
|
-
// of the map buffer
|
|
99
|
-
int32_t dynamicDataOffset = getDynamicDataOffset();
|
|
100
|
-
|
|
101
|
-
int32_t offset = getInt(key);
|
|
102
|
-
int32_t mapBufferLength = *reinterpret_cast<int32_t const *>(
|
|
103
|
-
bytes_.data() + dynamicDataOffset + offset);
|
|
104
|
-
|
|
105
|
-
std::vector<uint8_t> value(mapBufferLength);
|
|
106
|
-
|
|
107
|
-
memcpy(
|
|
108
|
-
value.data(),
|
|
109
|
-
bytes_.data() + dynamicDataOffset + offset + sizeof(int32_t),
|
|
110
|
-
mapBufferLength);
|
|
111
|
-
|
|
112
|
-
return MapBuffer(std::move(value));
|
|
113
|
-
}
|
|
114
|
-
|
|
115
|
-
size_t MapBuffer::size() const {
|
|
116
|
-
return bytes_.size();
|
|
117
|
-
}
|
|
118
|
-
|
|
119
|
-
uint8_t const *MapBuffer::data() const {
|
|
120
|
-
return bytes_.data();
|
|
121
|
-
}
|
|
122
|
-
|
|
123
|
-
uint16_t MapBuffer::count() const {
|
|
124
|
-
return count_;
|
|
125
|
-
}
|
|
126
|
-
|
|
127
|
-
} // namespace react
|
|
128
|
-
} // namespace facebook
|
|
@@ -1,150 +0,0 @@
|
|
|
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
|
-
#pragma once
|
|
9
|
-
|
|
10
|
-
#include <react/debug/react_native_assert.h>
|
|
11
|
-
|
|
12
|
-
#include <glog/logging.h>
|
|
13
|
-
|
|
14
|
-
#include <cstdint>
|
|
15
|
-
#include <cstdlib>
|
|
16
|
-
#include <limits>
|
|
17
|
-
#include <string>
|
|
18
|
-
#include <vector>
|
|
19
|
-
|
|
20
|
-
namespace facebook {
|
|
21
|
-
namespace react {
|
|
22
|
-
|
|
23
|
-
class ReadableMapBuffer;
|
|
24
|
-
|
|
25
|
-
// clang-format off
|
|
26
|
-
|
|
27
|
-
/**
|
|
28
|
-
* MapBuffer is an optimized sparse array format for transferring props-like
|
|
29
|
-
* between C++ and other VMs. The implementation of this map is optimized to:
|
|
30
|
-
* - be compact to optimize space when sparse (sparse is the common case).
|
|
31
|
-
* - be accessible through JNI with zero/minimal copying via ByteBuffer.
|
|
32
|
-
* - Have excellent C++ single-write and many-read performance by maximizing
|
|
33
|
-
* CPU cache performance through compactness, data locality, and fixed offsets
|
|
34
|
-
* where possible.
|
|
35
|
-
* - be optimized for iteration and intersection against other maps, but with
|
|
36
|
-
* reasonably good random access as well.
|
|
37
|
-
* - Work recursively for nested maps/arrays.
|
|
38
|
-
* - Supports dynamic types that map to JSON.
|
|
39
|
-
* - Don't require mutability - single-write on creation.
|
|
40
|
-
* - have minimal APK size and build time impact.
|
|
41
|
-
*
|
|
42
|
-
* MapBuffer data is stored in a continuous chunk of memory (bytes_ field below) with the following layout:
|
|
43
|
-
*
|
|
44
|
-
* ┌─────────────────────Header──────────────────────┐
|
|
45
|
-
* │ 10 bytes │
|
|
46
|
-
* ├─Alignment─┬─Item count─┬──────Buffer size───────┤
|
|
47
|
-
* │ 2 bytes │ 2 bytes │ 4 bytes │
|
|
48
|
-
* └───────────┴────────────┴────────────────────────┘
|
|
49
|
-
* ┌────────────────────────────────────────────────────────────────────────────────────────┐
|
|
50
|
-
* │ Buckets (one per item in the map) │
|
|
51
|
-
* │ │
|
|
52
|
-
* ├───────────────────────────Bucket───────────────────────────┬───Bucket────┬─────────────┤
|
|
53
|
-
* │ 12 bytes │ 12 bytes │ │
|
|
54
|
-
* ├───Key───┬──Type───┬──────Value (primitive or offset)───────┤ ... │ ... │
|
|
55
|
-
* │ 2 bytes │ 2 bytes │ 8 bytes │ │ │
|
|
56
|
-
* └─────────┴─────────┴────────────────────────────────────────┴─────────────┴─────────────┘
|
|
57
|
-
* ┌────────────────────────────────────────────────────────────────────────────────────────┐
|
|
58
|
-
* │ Dynamic data │
|
|
59
|
-
* │ │
|
|
60
|
-
* │ Free-form data for complex objects (e.g. strings or nested MapBuffers). │
|
|
61
|
-
* │ When dynamic data is serialized with some object, bucket value contains an offset of │
|
|
62
|
-
* │ associated byte in the array. The format of the data is not restricted, but common │
|
|
63
|
-
* │ practice is to use [length | bytes]. │
|
|
64
|
-
* └────────────────────────────────────────────────────────────────────────────────────────┘
|
|
65
|
-
*/
|
|
66
|
-
|
|
67
|
-
// clang-format on
|
|
68
|
-
|
|
69
|
-
class MapBuffer {
|
|
70
|
-
public:
|
|
71
|
-
using Key = uint16_t;
|
|
72
|
-
|
|
73
|
-
// The first value in the buffer, used to check correct encoding/endianness on
|
|
74
|
-
// JVM side.
|
|
75
|
-
constexpr static uint16_t HEADER_ALIGNMENT = 0xFE;
|
|
76
|
-
|
|
77
|
-
struct Header {
|
|
78
|
-
uint16_t alignment = HEADER_ALIGNMENT; // alignment of serialization
|
|
79
|
-
uint16_t count; // amount of items in the map
|
|
80
|
-
uint32_t bufferSize; // Amount of bytes used to store the map in memory
|
|
81
|
-
};
|
|
82
|
-
|
|
83
|
-
#pragma pack(1)
|
|
84
|
-
struct Bucket {
|
|
85
|
-
Key key;
|
|
86
|
-
uint16_t type;
|
|
87
|
-
uint64_t data;
|
|
88
|
-
|
|
89
|
-
Bucket(Key key, uint16_t type, uint64_t data)
|
|
90
|
-
: key(key), type(type), data(data) {}
|
|
91
|
-
};
|
|
92
|
-
|
|
93
|
-
static_assert(sizeof(Header) == 8, "MapBuffer header size is incorrect.");
|
|
94
|
-
static_assert(sizeof(Bucket) == 12, "MapBuffer bucket size is incorrect");
|
|
95
|
-
|
|
96
|
-
/**
|
|
97
|
-
* Data types available for serialization in MapBuffer
|
|
98
|
-
* Keep in sync with `DataType` enum in `ReadableMapBuffer.java`, which
|
|
99
|
-
* expects the same values after reading them through JNI.
|
|
100
|
-
*/
|
|
101
|
-
enum DataType : uint16_t {
|
|
102
|
-
Boolean = 0,
|
|
103
|
-
Int = 1,
|
|
104
|
-
Double = 2,
|
|
105
|
-
String = 3,
|
|
106
|
-
Map = 4,
|
|
107
|
-
};
|
|
108
|
-
|
|
109
|
-
explicit MapBuffer(std::vector<uint8_t> data);
|
|
110
|
-
|
|
111
|
-
MapBuffer(MapBuffer const &buffer) = delete;
|
|
112
|
-
|
|
113
|
-
MapBuffer &operator=(MapBuffer other) = delete;
|
|
114
|
-
|
|
115
|
-
MapBuffer(MapBuffer &&buffer) = default;
|
|
116
|
-
|
|
117
|
-
int32_t getInt(MapBuffer::Key key) const;
|
|
118
|
-
|
|
119
|
-
bool getBool(MapBuffer::Key key) const;
|
|
120
|
-
|
|
121
|
-
double getDouble(MapBuffer::Key key) const;
|
|
122
|
-
|
|
123
|
-
std::string getString(MapBuffer::Key key) const;
|
|
124
|
-
|
|
125
|
-
// TODO T83483191: review this declaration
|
|
126
|
-
MapBuffer getMapBuffer(MapBuffer::Key key) const;
|
|
127
|
-
|
|
128
|
-
size_t size() const;
|
|
129
|
-
|
|
130
|
-
uint8_t const *data() const;
|
|
131
|
-
|
|
132
|
-
uint16_t count() const;
|
|
133
|
-
|
|
134
|
-
private:
|
|
135
|
-
// Buffer and its size
|
|
136
|
-
std::vector<uint8_t> const bytes_;
|
|
137
|
-
|
|
138
|
-
// amount of items in the MapBuffer
|
|
139
|
-
uint16_t count_ = 0;
|
|
140
|
-
|
|
141
|
-
// returns the relative offset of the first byte of dynamic data
|
|
142
|
-
int32_t getDynamicDataOffset() const;
|
|
143
|
-
|
|
144
|
-
int32_t getKeyBucket(MapBuffer::Key key) const;
|
|
145
|
-
|
|
146
|
-
friend ReadableMapBuffer;
|
|
147
|
-
};
|
|
148
|
-
|
|
149
|
-
} // namespace react
|
|
150
|
-
} // namespace facebook
|
package/ReactCommon/TEMP_UntilReactCommonUpdate/react/renderer/mapbuffer/MapBufferBuilder.cpp
DELETED
|
@@ -1,149 +0,0 @@
|
|
|
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
|
-
#include "MapBufferBuilder.h"
|
|
9
|
-
#include <algorithm>
|
|
10
|
-
|
|
11
|
-
using namespace facebook::react;
|
|
12
|
-
|
|
13
|
-
namespace facebook {
|
|
14
|
-
namespace react {
|
|
15
|
-
|
|
16
|
-
constexpr uint32_t INT_SIZE = sizeof(uint32_t);
|
|
17
|
-
constexpr double DOUBLE_SIZE = sizeof(double);
|
|
18
|
-
constexpr uint32_t MAX_BUCKET_VALUE_SIZE = sizeof(uint64_t);
|
|
19
|
-
|
|
20
|
-
MapBuffer MapBufferBuilder::EMPTY() {
|
|
21
|
-
return MapBufferBuilder(0).build();
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
MapBufferBuilder::MapBufferBuilder(uint32_t initialSize) {
|
|
25
|
-
buckets_.reserve(initialSize);
|
|
26
|
-
header_.count = 0;
|
|
27
|
-
header_.bufferSize = 0;
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
void MapBufferBuilder::storeKeyValue(
|
|
31
|
-
MapBuffer::Key key,
|
|
32
|
-
MapBuffer::DataType type,
|
|
33
|
-
uint8_t const *value,
|
|
34
|
-
uint32_t valueSize) {
|
|
35
|
-
if (valueSize > MAX_BUCKET_VALUE_SIZE) {
|
|
36
|
-
LOG(ERROR) << "Error: size of value must be <= MAX_VALUE_SIZE. ValueSize: "
|
|
37
|
-
<< valueSize;
|
|
38
|
-
abort();
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
uint64_t data = 0;
|
|
42
|
-
auto *dataPtr = reinterpret_cast<uint8_t *>(&data);
|
|
43
|
-
memcpy(dataPtr, value, valueSize);
|
|
44
|
-
|
|
45
|
-
buckets_.emplace_back(key, static_cast<uint16_t>(type), data);
|
|
46
|
-
|
|
47
|
-
header_.count++;
|
|
48
|
-
|
|
49
|
-
if (lastKey_ > key) {
|
|
50
|
-
needsSort_ = true;
|
|
51
|
-
}
|
|
52
|
-
lastKey_ = key;
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
void MapBufferBuilder::putBool(MapBuffer::Key key, bool value) {
|
|
56
|
-
int intValue = (int)value;
|
|
57
|
-
storeKeyValue(
|
|
58
|
-
key,
|
|
59
|
-
MapBuffer::DataType::Boolean,
|
|
60
|
-
reinterpret_cast<uint8_t const *>(&intValue),
|
|
61
|
-
INT_SIZE);
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
void MapBufferBuilder::putDouble(MapBuffer::Key key, double value) {
|
|
65
|
-
storeKeyValue(
|
|
66
|
-
key,
|
|
67
|
-
MapBuffer::DataType::Double,
|
|
68
|
-
reinterpret_cast<uint8_t const *>(&value),
|
|
69
|
-
static_cast<uint32_t>(DOUBLE_SIZE));
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
void MapBufferBuilder::putInt(MapBuffer::Key key, int32_t value) {
|
|
73
|
-
storeKeyValue(
|
|
74
|
-
key,
|
|
75
|
-
MapBuffer::DataType::Int,
|
|
76
|
-
reinterpret_cast<uint8_t const *>(&value),
|
|
77
|
-
INT_SIZE);
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
void MapBufferBuilder::putString(MapBuffer::Key key, std::string const &value) {
|
|
81
|
-
auto strSize = value.size();
|
|
82
|
-
const char *strData = value.data();
|
|
83
|
-
|
|
84
|
-
// format [length of string (int)] + [Array of Characters in the string]
|
|
85
|
-
auto offset = dynamicData_.size();
|
|
86
|
-
dynamicData_.resize(offset + INT_SIZE + strSize, 0);
|
|
87
|
-
memcpy(dynamicData_.data() + offset, &strSize, INT_SIZE);
|
|
88
|
-
memcpy(dynamicData_.data() + offset + INT_SIZE, strData, strSize);
|
|
89
|
-
|
|
90
|
-
// Store Key and pointer to the string
|
|
91
|
-
storeKeyValue(
|
|
92
|
-
key,
|
|
93
|
-
MapBuffer::DataType::String,
|
|
94
|
-
reinterpret_cast<uint8_t const *>(&offset),
|
|
95
|
-
INT_SIZE);
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
void MapBufferBuilder::putMapBuffer(MapBuffer::Key key, MapBuffer const &map) {
|
|
99
|
-
auto mapBufferSize = map.size();
|
|
100
|
-
|
|
101
|
-
auto offset = dynamicData_.size();
|
|
102
|
-
|
|
103
|
-
// format [length of buffer (int)] + [bytes of MapBuffer]
|
|
104
|
-
dynamicData_.resize(offset + INT_SIZE + mapBufferSize, 0);
|
|
105
|
-
memcpy(dynamicData_.data() + offset, &mapBufferSize, INT_SIZE);
|
|
106
|
-
// Copy the content of the map into dynamicData_
|
|
107
|
-
memcpy(dynamicData_.data() + offset + INT_SIZE, map.data(), mapBufferSize);
|
|
108
|
-
|
|
109
|
-
// Store Key and pointer to the string
|
|
110
|
-
storeKeyValue(
|
|
111
|
-
key,
|
|
112
|
-
MapBuffer::DataType::Map,
|
|
113
|
-
reinterpret_cast<uint8_t const *>(&offset),
|
|
114
|
-
INT_SIZE);
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
static inline bool compareBuckets(
|
|
118
|
-
MapBuffer::Bucket const &a,
|
|
119
|
-
MapBuffer::Bucket const &b) {
|
|
120
|
-
return a.key < b.key;
|
|
121
|
-
}
|
|
122
|
-
|
|
123
|
-
MapBuffer MapBufferBuilder::build() {
|
|
124
|
-
// Create buffer: [header] + [key, values] + [dynamic data]
|
|
125
|
-
auto bucketSize = buckets_.size() * sizeof(MapBuffer::Bucket);
|
|
126
|
-
auto headerSize = sizeof(MapBuffer::Header);
|
|
127
|
-
auto bufferSize = headerSize + bucketSize + dynamicData_.size();
|
|
128
|
-
|
|
129
|
-
header_.bufferSize = static_cast<uint32_t>(bufferSize);
|
|
130
|
-
|
|
131
|
-
if (needsSort_) {
|
|
132
|
-
std::sort(buckets_.begin(), buckets_.end(), compareBuckets);
|
|
133
|
-
}
|
|
134
|
-
|
|
135
|
-
// TODO(T83483191): add pass to check for duplicates
|
|
136
|
-
|
|
137
|
-
std::vector<uint8_t> buffer(bufferSize);
|
|
138
|
-
memcpy(buffer.data(), &header_, headerSize);
|
|
139
|
-
memcpy(buffer.data() + headerSize, buckets_.data(), bucketSize);
|
|
140
|
-
memcpy(
|
|
141
|
-
buffer.data() + headerSize + bucketSize,
|
|
142
|
-
dynamicData_.data(),
|
|
143
|
-
dynamicData_.size());
|
|
144
|
-
|
|
145
|
-
return MapBuffer(std::move(buffer));
|
|
146
|
-
}
|
|
147
|
-
|
|
148
|
-
} // namespace react
|
|
149
|
-
} // namespace facebook
|
|
@@ -1,59 +0,0 @@
|
|
|
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
|
-
#pragma once
|
|
9
|
-
|
|
10
|
-
#include <react/debug/react_native_assert.h>
|
|
11
|
-
#include <react/renderer/mapbuffer/MapBuffer.h>
|
|
12
|
-
|
|
13
|
-
namespace facebook {
|
|
14
|
-
namespace react {
|
|
15
|
-
|
|
16
|
-
// Default reserved size for buckets_ vector
|
|
17
|
-
constexpr uint32_t INITIAL_BUCKETS_SIZE = 10;
|
|
18
|
-
|
|
19
|
-
/**
|
|
20
|
-
* MapBufferBuilder is a builder class for MapBuffer
|
|
21
|
-
*/
|
|
22
|
-
class MapBufferBuilder {
|
|
23
|
-
public:
|
|
24
|
-
MapBufferBuilder(uint32_t initialSize = INITIAL_BUCKETS_SIZE);
|
|
25
|
-
|
|
26
|
-
static MapBuffer EMPTY();
|
|
27
|
-
|
|
28
|
-
void putInt(MapBuffer::Key key, int32_t value);
|
|
29
|
-
|
|
30
|
-
void putBool(MapBuffer::Key key, bool value);
|
|
31
|
-
|
|
32
|
-
void putDouble(MapBuffer::Key key, double value);
|
|
33
|
-
|
|
34
|
-
void putString(MapBuffer::Key key, std::string const &value);
|
|
35
|
-
|
|
36
|
-
void putMapBuffer(MapBuffer::Key key, MapBuffer const &map);
|
|
37
|
-
|
|
38
|
-
MapBuffer build();
|
|
39
|
-
|
|
40
|
-
private:
|
|
41
|
-
MapBuffer::Header header_;
|
|
42
|
-
|
|
43
|
-
std::vector<MapBuffer::Bucket> buckets_{};
|
|
44
|
-
|
|
45
|
-
std::vector<uint8_t> dynamicData_{};
|
|
46
|
-
|
|
47
|
-
uint16_t lastKey_{0};
|
|
48
|
-
|
|
49
|
-
bool needsSort_{false};
|
|
50
|
-
|
|
51
|
-
void storeKeyValue(
|
|
52
|
-
MapBuffer::Key key,
|
|
53
|
-
MapBuffer::DataType type,
|
|
54
|
-
uint8_t const *value,
|
|
55
|
-
uint32_t valueSize);
|
|
56
|
-
};
|
|
57
|
-
|
|
58
|
-
} // namespace react
|
|
59
|
-
} // namespace facebook
|
package/ReactCommon/TEMP_UntilReactCommonUpdate/react/renderer/mapbuffer/tests/MapBufferTest.cpp
DELETED
|
@@ -1,167 +0,0 @@
|
|
|
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
|
-
#include <memory>
|
|
9
|
-
|
|
10
|
-
#include <gtest/gtest.h>
|
|
11
|
-
#pragma pack(pop, 1)
|
|
12
|
-
#include <react/renderer/mapbuffer/MapBuffer.h>
|
|
13
|
-
#include <react/renderer/mapbuffer/MapBufferBuilder.h>
|
|
14
|
-
|
|
15
|
-
using namespace facebook::react;
|
|
16
|
-
|
|
17
|
-
TEST(MapBufferTest, testSimpleIntMap) {
|
|
18
|
-
auto builder = MapBufferBuilder();
|
|
19
|
-
|
|
20
|
-
builder.putInt(0, 1234);
|
|
21
|
-
builder.putInt(1, 4321);
|
|
22
|
-
|
|
23
|
-
auto map = builder.build();
|
|
24
|
-
|
|
25
|
-
EXPECT_EQ(map.count(), 2);
|
|
26
|
-
EXPECT_EQ(map.getInt(0), 1234);
|
|
27
|
-
EXPECT_EQ(map.getInt(1), 4321);
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
TEST(MapBufferTest, testMapBufferExtension) {
|
|
31
|
-
// 26 = 2 buckets: 2*10 + 6 sizeof(header)
|
|
32
|
-
int initialSize = 26;
|
|
33
|
-
auto buffer = MapBufferBuilder(initialSize);
|
|
34
|
-
|
|
35
|
-
buffer.putInt(0, 1234);
|
|
36
|
-
buffer.putInt(1, 4321);
|
|
37
|
-
buffer.putInt(2, 2121);
|
|
38
|
-
buffer.putInt(3, 1212);
|
|
39
|
-
|
|
40
|
-
auto map = buffer.build();
|
|
41
|
-
|
|
42
|
-
EXPECT_EQ(map.count(), 4);
|
|
43
|
-
|
|
44
|
-
EXPECT_EQ(map.getInt(0), 1234);
|
|
45
|
-
EXPECT_EQ(map.getInt(1), 4321);
|
|
46
|
-
EXPECT_EQ(map.getInt(2), 2121);
|
|
47
|
-
EXPECT_EQ(map.getInt(3), 1212);
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
TEST(MapBufferTest, testBoolEntries) {
|
|
51
|
-
auto buffer = MapBufferBuilder();
|
|
52
|
-
|
|
53
|
-
buffer.putBool(0, true);
|
|
54
|
-
buffer.putBool(1, false);
|
|
55
|
-
|
|
56
|
-
auto map = buffer.build();
|
|
57
|
-
|
|
58
|
-
EXPECT_EQ(map.count(), 2);
|
|
59
|
-
EXPECT_EQ(map.getBool(0), true);
|
|
60
|
-
EXPECT_EQ(map.getBool(1), false);
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
TEST(MapBufferTest, testDoubleEntries) {
|
|
64
|
-
auto buffer = MapBufferBuilder();
|
|
65
|
-
|
|
66
|
-
buffer.putDouble(0, 123.4);
|
|
67
|
-
buffer.putDouble(1, 432.1);
|
|
68
|
-
|
|
69
|
-
auto map = buffer.build();
|
|
70
|
-
|
|
71
|
-
EXPECT_EQ(map.count(), 2);
|
|
72
|
-
|
|
73
|
-
EXPECT_EQ(map.getDouble(0), 123.4);
|
|
74
|
-
EXPECT_EQ(map.getDouble(1), 432.1);
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
TEST(MapBufferTest, testStringEntries) {
|
|
78
|
-
auto builder = MapBufferBuilder();
|
|
79
|
-
|
|
80
|
-
builder.putString(0, "This is a test");
|
|
81
|
-
auto map = builder.build();
|
|
82
|
-
|
|
83
|
-
EXPECT_EQ(map.getString(0), "This is a test");
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
TEST(MapBufferTest, testUTFStringEntry) {
|
|
87
|
-
auto builder = MapBufferBuilder();
|
|
88
|
-
|
|
89
|
-
builder.putString(0, "Let's count: 的, 一, 是");
|
|
90
|
-
auto map = builder.build();
|
|
91
|
-
|
|
92
|
-
EXPECT_EQ(map.getString(0), "Let's count: 的, 一, 是");
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
TEST(MapBufferTest, testEmojiStringEntry) {
|
|
96
|
-
auto builder = MapBufferBuilder();
|
|
97
|
-
|
|
98
|
-
builder.putString(
|
|
99
|
-
0, "Let's count: 1️⃣, 2️⃣, 3️⃣, 🤦🏿♀️");
|
|
100
|
-
auto map = builder.build();
|
|
101
|
-
|
|
102
|
-
EXPECT_EQ(
|
|
103
|
-
map.getString(0),
|
|
104
|
-
"Let's count: 1️⃣, 2️⃣, 3️⃣, 🤦🏿♀️");
|
|
105
|
-
}
|
|
106
|
-
|
|
107
|
-
TEST(MapBufferTest, testUTFStringEntries) {
|
|
108
|
-
auto builder = MapBufferBuilder();
|
|
109
|
-
|
|
110
|
-
builder.putString(0, "Let's count: 的, 一, 是");
|
|
111
|
-
builder.putString(1, "This is a test");
|
|
112
|
-
auto map = builder.build();
|
|
113
|
-
|
|
114
|
-
EXPECT_EQ(map.getString(0), "Let's count: 的, 一, 是");
|
|
115
|
-
EXPECT_EQ(map.getString(1), "This is a test");
|
|
116
|
-
}
|
|
117
|
-
|
|
118
|
-
TEST(MapBufferTest, testEmptyMap) {
|
|
119
|
-
auto builder = MapBufferBuilder();
|
|
120
|
-
auto map = builder.build();
|
|
121
|
-
EXPECT_EQ(map.count(), 0);
|
|
122
|
-
}
|
|
123
|
-
|
|
124
|
-
TEST(MapBufferTest, testEmptyMapConstant) {
|
|
125
|
-
auto map = MapBufferBuilder::EMPTY();
|
|
126
|
-
EXPECT_EQ(map.count(), 0);
|
|
127
|
-
}
|
|
128
|
-
|
|
129
|
-
TEST(MapBufferTest, testMapEntries) {
|
|
130
|
-
auto builder = MapBufferBuilder();
|
|
131
|
-
builder.putString(0, "This is a test");
|
|
132
|
-
builder.putInt(1, 1234);
|
|
133
|
-
auto map = builder.build();
|
|
134
|
-
|
|
135
|
-
EXPECT_EQ(map.count(), 2);
|
|
136
|
-
EXPECT_EQ(map.getString(0), "This is a test");
|
|
137
|
-
EXPECT_EQ(map.getInt(1), 1234);
|
|
138
|
-
|
|
139
|
-
auto builder2 = MapBufferBuilder();
|
|
140
|
-
builder2.putInt(0, 4321);
|
|
141
|
-
builder2.putMapBuffer(1, map);
|
|
142
|
-
auto map2 = builder2.build();
|
|
143
|
-
|
|
144
|
-
EXPECT_EQ(map2.count(), 2);
|
|
145
|
-
EXPECT_EQ(map2.getInt(0), 4321);
|
|
146
|
-
|
|
147
|
-
MapBuffer readMap2 = map2.getMapBuffer(1);
|
|
148
|
-
|
|
149
|
-
EXPECT_EQ(readMap2.count(), 2);
|
|
150
|
-
EXPECT_EQ(readMap2.getString(0), "This is a test");
|
|
151
|
-
EXPECT_EQ(readMap2.getInt(1), 1234);
|
|
152
|
-
}
|
|
153
|
-
|
|
154
|
-
TEST(MapBufferTest, testMapRandomAccess) {
|
|
155
|
-
auto builder = MapBufferBuilder();
|
|
156
|
-
builder.putInt(1234, 4321);
|
|
157
|
-
builder.putString(0, "This is a test");
|
|
158
|
-
builder.putDouble(8, 908.1);
|
|
159
|
-
builder.putString(65535, "Let's count: 的, 一, 是");
|
|
160
|
-
auto map = builder.build();
|
|
161
|
-
|
|
162
|
-
EXPECT_EQ(map.count(), 4);
|
|
163
|
-
EXPECT_EQ(map.getString(0), "This is a test");
|
|
164
|
-
EXPECT_EQ(map.getDouble(8), 908.1);
|
|
165
|
-
EXPECT_EQ(map.getInt(1234), 4321);
|
|
166
|
-
EXPECT_EQ(map.getString(65535), "Let's count: 的, 一, 是");
|
|
167
|
-
}
|