mirror of
https://github.com/facebook/react-native.git
synced 2025-11-01 09:14:26 +00:00
91b3f5d48a
Summary: This diff contains the code from the 35 diff stack - D27210587 This diff implement and integrates Mapbuffer into Fabric text measure system changelog: [internal] internal Reviewed By: JoshuaGross Differential Revision: D27241836 fbshipit-source-id: f40a780df0723f27da440f709a8676cfcca63953
93 lines
2.3 KiB
C++
93 lines
2.3 KiB
C++
/*
|
|
* Copyright (c) Facebook, Inc. and its affiliates.
|
|
*
|
|
* This source code is licensed under the MIT license found in the
|
|
* LICENSE file in the root directory of this source tree.
|
|
*/
|
|
|
|
#pragma once
|
|
|
|
#include <react/renderer/mapbuffer/MapBuffer.h>
|
|
#include <react/renderer/mapbuffer/primitives.h>
|
|
|
|
namespace facebook {
|
|
namespace react {
|
|
|
|
// Default initial size for _keyValues array
|
|
// 106 = 10 entries = 10*10 + 6 sizeof(header)
|
|
constexpr uint16_t INITIAL_KEY_VALUE_SIZE = 106;
|
|
|
|
// Default initial size for _dynamicDataValues array
|
|
constexpr int INITIAL_DYNAMIC_DATA_SIZE = 200;
|
|
|
|
/**
|
|
* MapBufferBuilder is a builder class for MapBuffer
|
|
*/
|
|
class MapBufferBuilder {
|
|
private:
|
|
Header _header = {ALIGNMENT, 0, 0};
|
|
|
|
void ensureKeyValueSpace();
|
|
|
|
void ensureDynamicDataSpace(int size);
|
|
|
|
void storeKeyValue(Key key, uint8_t *value, int valueSize);
|
|
|
|
// Array of [key,value] map entries:
|
|
// - Key is represented in 2 bytes
|
|
// - Value is stored into 8 bytes. The 8 bytes of the value will contain the
|
|
// actual value for the key or a pointer to the actual value (based on the
|
|
// type)
|
|
uint8_t *_keyValues;
|
|
|
|
// Amount of bytes allocated on _keyValues
|
|
uint16_t _keyValuesSize;
|
|
|
|
// Relative offset on the _keyValues array.
|
|
// This represents the first byte that can be written in _keyValues array
|
|
int _keyValuesOffset;
|
|
|
|
// This array contains data for dynamic values in the MapBuffer.
|
|
// A dynamic value is a String or another MapBuffer.
|
|
uint8_t *_dynamicDataValues;
|
|
|
|
// Amount of bytes allocated on _dynamicDataValues
|
|
uint16_t _dynamicDataSize;
|
|
|
|
// Relative offset on the _dynamicDataValues array.
|
|
// This represents the first byte that can be written in _dynamicDataValues
|
|
// array
|
|
int _dynamicDataOffset;
|
|
|
|
// Minimmum key to store in the MapBuffer (this is used to guarantee
|
|
// consistency)
|
|
uint16_t _minKeyToStore = 0;
|
|
|
|
public:
|
|
MapBufferBuilder();
|
|
|
|
MapBufferBuilder(uint16_t initialSize);
|
|
|
|
~MapBufferBuilder();
|
|
|
|
static MapBuffer EMPTY();
|
|
|
|
void putInt(Key key, int value);
|
|
|
|
void putBool(Key key, bool value);
|
|
|
|
void putDouble(Key key, double value);
|
|
|
|
void putNull(Key key);
|
|
|
|
void putString(Key key, std::string value);
|
|
|
|
void putMapBuffer(Key key, MapBuffer &map);
|
|
|
|
// TODO This should return MapBuffer!
|
|
MapBuffer build();
|
|
};
|
|
|
|
} // namespace react
|
|
} // namespace facebook
|