first commit

This commit is contained in:
2026-03-10 16:18:05 +00:00
commit 11f9c069b5
31635 changed files with 3187747 additions and 0 deletions

View File

@@ -0,0 +1,31 @@
# 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.
require "json"
package = JSON.parse(File.read(File.join(__dir__, "..", "..", "package.json")))
version = package['version']
source = { :git => 'https://github.com/facebook/react-native.git' }
if version == '1000.0.0'
# This is an unpublished version, use the latest commit hash of the react-native repo, which were presumably in.
source[:commit] = `git rev-parse HEAD`.strip if system("git rev-parse --git-dir > /dev/null 2>&1")
else
source[:tag] = "v#{version}"
end
Pod::Spec.new do |s|
s.name = "FBLazyVector"
s.version = version
s.summary = "-" # TODO
s.homepage = "https://reactnative.dev/"
s.license = package["license"]
s.author = "Meta Platforms, Inc. and its affiliates"
s.platforms = min_supported_versions
s.source = source
s.source_files = podspec_sources("**/*.{c,h,m,mm,cpp}", "**/*.h")
s.header_dir = "FBLazyVector"
end

View File

@@ -0,0 +1,143 @@
/*
* 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.
*/
#pragma once
#import <functional>
#import <iterator>
namespace FB {
template <typename T, typename U>
class LazyIterator {
public:
using value_type = T;
using pointer = std::unique_ptr<T>;
using reference = T;
using iterator_category = std::random_access_iterator_tag;
using difference_type = std::int32_t;
using size_type = std::int32_t;
using convert_type = std::function<T(U)>;
public:
LazyIterator() = default;
LazyIterator(U vector, convert_type convert, size_type i) : _v(vector), _i(i), _convert(std::move(convert)) {}
bool operator==(const LazyIterator &other) const
{
return _i == other._i && _v == other._v;
}
bool operator<(const LazyIterator &b) const
{
return _i < b._i;
}
value_type operator*() const
{
return _convert(_v[_i]);
}
std::unique_ptr<value_type> operator->() const
{
return std::make_unique<value_type>(*this);
}
LazyIterator operator+(difference_type n) const
{
return LazyIterator(_v, _convert, _i + n);
}
LazyIterator &operator+=(difference_type n)
{
_i += n;
return *this;
}
LazyIterator &operator-=(difference_type n)
{
_i -= n;
return *this;
}
LazyIterator operator-(difference_type n) const
{
return LazyIterator(_v, _i - n);
}
difference_type operator-(const LazyIterator &a) const
{
return _i - a._i;
}
LazyIterator &operator++()
{
return *this += 1;
}
LazyIterator operator++(int)
{
auto tmp = *this;
++*this;
return tmp;
}
LazyIterator &operator--()
{
return *this -= 1;
}
LazyIterator operator--(int)
{
auto tmp = *this;
--*this;
return tmp;
}
value_type operator[](difference_type n) const
{
return _convert(_v[_i + n]);
}
private:
U _v;
size_type _i;
convert_type _convert;
};
template <typename T, typename U>
LazyIterator<T, U> operator+(typename LazyIterator<T, U>::difference_type n, const LazyIterator<T, U> &i)
{
return i + n;
}
template <typename T, typename U>
bool operator!=(const LazyIterator<T, U> &a, const LazyIterator<T, U> &b)
{
return !(a == b);
}
template <typename T, typename U>
bool operator<=(const LazyIterator<T, U> &a, const LazyIterator<T, U> &b)
{
return a < b || a == b;
}
template <typename T, typename U>
bool operator>(const LazyIterator<T, U> &a, const LazyIterator<T, U> &b)
{
return b < a;
}
template <typename T, typename U>
bool operator>=(const LazyIterator<T, U> &a, const LazyIterator<T, U> &b)
{
return a > b || a == b;
}
} // namespace FB

View File

@@ -0,0 +1,113 @@
/*
* 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.
*/
#pragma once
#import <cassert>
#import <functional>
#import <iterator>
#import <FBLazyVector/FBLazyIterator.h>
namespace FB {
/**
* Presents a type-safe wrapper around an arbitrary object that represents an
* _immutable_ array of objects. Each item is constructed lazily on demand and
* reconstructed on each access; there is no caching.
*/
template <typename T, typename U>
class LazyVector {
public:
using value_type = T;
using reference = T;
using const_reference = T;
using const_iterator = LazyIterator<T, U>;
using iterator = const_iterator;
using size_type = std::int32_t;
using convert_type = std::function<T(U)>;
static LazyVector<T, U> fromUnsafeRawValue(U v, size_type size, convert_type convert)
{
return {v, size, convert};
}
U unsafeRawValue() const
{
return _v;
}
bool empty() const
{
return _size == 0;
}
size_type size() const
{
return _size;
}
const_reference at(size_type pos) const
{
#ifndef _LIBCPP_NO_EXCEPTIONS
if (!(pos < _size)) {
throw std::out_of_range("out of range");
}
#else
assert(pos < _size || !"out of range");
#endif
return _convert(_v[pos]);
}
const_reference operator[](size_type pos) const
{
assert(pos < _size);
return _convert(_v[pos]);
}
const_reference front() const
{
assert(_size);
return (*this)[0];
}
const_reference back() const
{
assert(_size);
return (*this)[_size - 1];
}
const_iterator begin() const
{
return const_iterator(_v, _convert, 0);
}
const_iterator cbegin() const
{
return begin();
}
const_iterator end() const
{
return const_iterator(_v, _convert, _size);
}
const_iterator cend() const
{
return end();
}
private:
/** Wrapped vector */
LazyVector(U vector, size_type size, convert_type convert) : _v(vector), _size(size), _convert(convert) {}
U _v;
size_type _size;
convert_type _convert;
};
} // namespace FB