Skip to content

Commit

Permalink
Remove Folly::small_vector (#39442)
Browse files Browse the repository at this point in the history
Summary:
Pull Request resolved: #39442

changelog: [internal]

Delete folly:small_vector. folly:small_vector was not used on Android, fragmenting platforms.
Additionally, we want to remove dependency on Folly from React Native.

Reviewed By: NickGerleman, rshest

Differential Revision: D48966287

fbshipit-source-id: 000b4d58d54b6100aeac016af53b5e5f8cbee705
  • Loading branch information
sammy-SC authored and facebook-github-bot committed Sep 16, 2023
1 parent 5bc7b1e commit d053137
Show file tree
Hide file tree
Showing 17 changed files with 26 additions and 114 deletions.
39 changes: 0 additions & 39 deletions packages/react-native/ReactCommon/butter/small_vector.h

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ class AttributedString : public Sealable, public DebugStringConvertible {
int length{0};
};

using Fragments = butter::small_vector<Fragment, 1>;
using Fragments = std::vector<Fragment>;

/*
* Appends and prepends a `fragment` to the string.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,7 @@ class YogaLayoutableShadowNode : public LayoutableShadowNode {

public:
using Shared = std::shared_ptr<const YogaLayoutableShadowNode>;
using ListOfShared =
butter::small_vector<Shared, kShadowNodeChildrenSmallVectorSize>;
using ListOfShared = std::vector<Shared>;

static ShadowNodeTraits BaseTraits();
static ShadowNodeTraits::Trait IdentifierTrait();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
namespace facebook::react {

template <class T>
using LayoutableSmallVector = butter::small_vector<T, 16>;
using LayoutableSmallVector = std::vector<T>;

static LayoutableSmallVector<Rect> calculateTransformedFrames(
const LayoutableSmallVector<ShadowNode const*>& shadowNodeList,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
#include <memory>
#include <vector>

#include <butter/small_vector.h>
#include <react/debug/react_native_assert.h>
#include <react/renderer/core/LayoutMetrics.h>
#include <react/renderer/core/ShadowNode.h>
Expand Down Expand Up @@ -49,8 +48,7 @@ class LayoutableShadowNode : public ShadowNode {
bool enableOverflowClipping{false};
};

using UnsharedList = butter::
small_vector<LayoutableShadowNode*, kShadowNodeChildrenSmallVectorSize>;
using UnsharedList = std::vector<LayoutableShadowNode*>;

/*
* Returns layout metrics of a node represented as `descendantNodeFamily`
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
#include <optional>

#include <butter/map.h>
#include <butter/small_vector.h>

#include <folly/dynamic.h>
#include <jsi/JSIDynamic.h>
Expand Down Expand Up @@ -132,12 +131,8 @@ class RawProps final {
* Parsed artefacts:
* To be used by `RawPropParser`.
*/
mutable butter::
small_vector<RawPropsValueIndex, kNumberOfPropsPerComponentSoftCap>
keyIndexToValueIndex_;
mutable butter::
small_vector<RawValue, kNumberOfExplicitlySpecifiedPropsSoftCap>
values_;
mutable std::vector<RawPropsValueIndex> keyIndexToValueIndex_;
mutable std::vector<RawValue> values_;
};

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

#pragma once

#include <butter/small_vector.h>

#include <react/renderer/core/RawPropsKey.h>
#include <react/renderer/core/RawPropsPrimitives.h>
#include <vector>

namespace facebook::react {

Expand Down Expand Up @@ -54,9 +53,8 @@ class RawPropsKeyMap final {
const Item& rhs) noexcept;
static bool hasSameName(const Item& lhs, const Item& rhs) noexcept;

butter::small_vector<Item, kNumberOfExplicitlySpecifiedPropsSoftCap> items_{};
butter::small_vector<RawPropsPropNameLength, kPropNameLengthHardCap>
buckets_{};
std::vector<Item> items_{};
std::vector<RawPropsPropNameLength> buckets_{};
};

} // namespace facebook::react
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
#pragma once

#include <butter/map.h>
#include <butter/small_vector.h>
#include <react/renderer/core/Props.h>
#include <react/renderer/core/PropsParserContext.h>
#include <react/renderer/core/RawProps.h>
Expand Down Expand Up @@ -84,8 +83,7 @@ class RawPropsParser final {
void(RawPropsPropNameHash, const char*, RawValue const&)>& visit)
const;

mutable butter::small_vector<RawPropsKey, kNumberOfPropsPerComponentSoftCap>
keys_{};
mutable std::vector<RawPropsKey> keys_{};
mutable RawPropsKeyMap nameToIndex_{};
mutable bool ready_{false};
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,26 +22,12 @@ static_assert(
using RawPropsPropNameLength = uint16_t;
using RawPropsPropNameHash = uint32_t;

/*
* The number which is *usually* bigger than a number of explicitly specified
* props for some component.
*/
constexpr static int kNumberOfExplicitlySpecifiedPropsSoftCap = 16;

/*
* Special value of `RawPropsValueIndex` which is used to represent `no value`.
*/
constexpr static RawPropsValueIndex kRawPropsValueIndexEmpty =
std::numeric_limits<RawPropsValueIndex>::max();

/*
* The number of props that usually more than `*Props` classes have.
* Should be roughly equal to the number of props inside `ViewProps` plus
* about twenty. It's okay if some `*Props` class has more than this amount of
* props but the majority of those classes should be below this cap.
*/
constexpr static auto kNumberOfPropsPerComponentSoftCap = 250;

/*
* The maximum length of the prop name.
* To process prop names efficiently we have to allocate the memory statically,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@
#include "DynamicPropsUtilities.h"
#include "ShadowNodeFragment.h"

#include <butter/small_vector.h>

#include <react/debug/react_native_assert.h>
#include <react/renderer/core/ComponentDescriptor.h>
#include <react/renderer/core/ShadowNodeFragment.h>
Expand Down
17 changes: 5 additions & 12 deletions packages/react-native/ReactCommon/react/renderer/core/ShadowNode.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
#include <type_traits>
#include <vector>

#include <butter/small_vector.h>
#include <react/renderer/core/EventEmitter.h>
#include <react/renderer/core/Props.h>
#include <react/renderer/core/ReactPrimitives.h>
Expand All @@ -24,8 +23,6 @@

namespace facebook::react {

static constexpr const int kShadowNodeChildrenSmallVectorSize = 8;

class ComponentDescriptor;
struct ShadowNodeFragment;

Expand All @@ -36,19 +33,15 @@ class ShadowNode : public Sealable,
using Shared = std::shared_ptr<const ShadowNode>;
using Weak = std::weak_ptr<const ShadowNode>;
using Unshared = std::shared_ptr<ShadowNode>;
using ListOfShared =
butter::small_vector<Shared, kShadowNodeChildrenSmallVectorSize>;
using ListOfWeak =
butter::small_vector<Weak, kShadowNodeChildrenSmallVectorSize>;
using ListOfShared = std::vector<Shared>;
using ListOfWeak = std::vector<Weak>;
using SharedListOfShared = std::shared_ptr<const ListOfShared>;
using UnsharedListOfShared = std::shared_ptr<ListOfShared>;
using UnsharedListOfWeak = std::shared_ptr<ListOfWeak>;

using AncestorList = butter::small_vector<
std::pair<
std::reference_wrapper<const ShadowNode> /* parentNode */,
int /* childIndex */>,
64>;
using AncestorList = std::vector<std::pair<
std::reference_wrapper<const ShadowNode> /* parentNode */,
int /* childIndex */>>;

static SharedListOfShared emptySharedShadowNodeSharedList();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ const ComponentDescriptor& ShadowNodeFamily::getComponentDescriptor() const {

AncestorList ShadowNodeFamily::getAncestors(
const ShadowNode& ancestorShadowNode) const {
auto families = butter::small_vector<const ShadowNodeFamily*, 64>{};
auto families = std::vector<const ShadowNodeFamily*>{};
auto ancestorFamily = ancestorShadowNode.family_.get();

auto family = this;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@
#include <memory>
#include <shared_mutex>

#include <butter/small_vector.h>

#include <react/renderer/core/EventEmitter.h>
#include <react/renderer/core/InstanceHandle.h>
#include <react/renderer/core/ReactPrimitives.h>
Expand Down Expand Up @@ -49,11 +47,9 @@ class ShadowNodeFamily final {
using Shared = std::shared_ptr<const ShadowNodeFamily>;
using Weak = std::weak_ptr<const ShadowNodeFamily>;

using AncestorList = butter::small_vector<
std::pair<
std::reference_wrapper<const ShadowNode> /* parentNode */,
int /* childIndex */>,
64>;
using AncestorList = std::vector<std::pair<
std::reference_wrapper<const ShadowNode> /* parentNode */,
int /* childIndex */>>;

ShadowNodeFamily(
const ShadowNodeFamilyFragment& fragment,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
#include <react/renderer/imagemanager/ImageResponse.h>
#include <react/renderer/imagemanager/ImageResponseObserver.h>

#include <butter/small_vector.h>
#include <mutex>
#include <vector>

Expand Down Expand Up @@ -58,7 +57,7 @@ class ImageResponseObserverCoordinator {
* List of observers.
* Mutable: protected by mutex_.
*/
mutable butter::small_vector<const ImageResponseObserver*, 1> observers_;
mutable std::vector<const ImageResponseObserver*> observers_;

/*
* Current status of image loading.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
#include "Differentiator.h"

#include <butter/map.h>
#include <butter/small_vector.h>
#include <react/debug/react_native_assert.h>
#include <react/renderer/core/LayoutableShadowNode.h>
#include <react/renderer/debug/SystraceSection.h>
Expand Down Expand Up @@ -62,7 +61,7 @@ namespace facebook::react {
* where a bunch of views appears on the screen first time); in this
* implementation, this is as performant as vector `push_back`.
*/
template <typename KeyT, typename ValueT, int DefaultSize = 16>
template <typename KeyT, typename ValueT>
class TinyMap final {
public:
using Pair = std::pair<KeyT, ValueT>;
Expand Down Expand Up @@ -167,7 +166,7 @@ class TinyMap final {
erasedAtFront_ = 0;
}

butter::small_vector<Pair, DefaultSize> vector_;
std::vector<Pair> vector_;
size_t numErased_{0};
size_t erasedAtFront_{0};
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@

#pragma once

#include <butter/small_vector.h>
#include <folly/Hash.h>
#include <react/renderer/core/EventEmitter.h>
#include <react/renderer/core/LayoutMetrics.h>
Expand Down Expand Up @@ -64,10 +63,8 @@ std::vector<DebugStringConvertibleObject> getDebugProps(
*
*/
struct ShadowViewNodePair final {
using NonOwningList = butter::
small_vector<ShadowViewNodePair*, kShadowNodeChildrenSmallVectorSize>;
using OwningList = butter::
small_vector<ShadowViewNodePair, kShadowNodeChildrenSmallVectorSize>;
using NonOwningList = std::vector<ShadowViewNodePair*>;
using OwningList = std::vector<ShadowViewNodePair>;

ShadowView shadowView;
const ShadowNode* shadowNode;
Expand Down Expand Up @@ -102,9 +99,7 @@ struct ShadowViewNodePair final {
*
*/
struct ShadowViewNodePairLegacy final {
using OwningList = butter::small_vector<
ShadowViewNodePairLegacy,
kShadowNodeChildrenSmallVectorSize>;
using OwningList = std::vector<ShadowViewNodePairLegacy>;

ShadowView shadowView;
const ShadowNode* shadowNode;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@

#pragma once

#include <butter/small_vector.h>
#include <vector>

#include <react/renderer/telemetry/TransactionTelemetry.h>
Expand Down Expand Up @@ -59,9 +58,7 @@ class SurfaceTelemetry final {
int numberOfTextMeasurements_{};
int lastRevisionNumber_{};

butter::
small_vector<TransactionTelemetry, kMaxNumberOfRecordedCommitTelemetries>
recentTransactionTelemetries_{};
std::vector<TransactionTelemetry> recentTransactionTelemetries_{};
};

} // namespace facebook::react

0 comments on commit d053137

Please sign in to comment.