mirror of
https://github.com/zoriya/nitro.git
synced 2026-10-13 00:05:23 +00:00
* feat: Create `PropNameID` Cache * Impl PropNameID * fix: Use `const jsi::PropNameID&` instead of `BorrowingReference` * perf: Use `PropNameIDCache` everywhere internally * fix: Make use of `PropNameIDCache` in custom user defined structs * fix: Use `PropNameIDCache` for Hybrid Views too * fix: `jsi::Runtime` deref * fix: Allow `JSICache` to use itself by caching itself first * fix: Remove `allowCache` flag * perf: Avoid `BorrowingReference<T>` copy and use `const T&` * perf: Use `PropNameIDCache` inside `defineProperty(...)` * docs: Add docs
45 lines
1.1 KiB
C++
45 lines
1.1 KiB
C++
//
|
|
// PropNameIDCache.hpp
|
|
// react-native-nitro
|
|
//
|
|
// Created by Marc Rousavy on 17.10.25.
|
|
//
|
|
|
|
#pragma once
|
|
|
|
#include "BorrowingReference.hpp"
|
|
#include <jsi/jsi.h>
|
|
#include <unordered_map>
|
|
|
|
namespace margelo::nitro {
|
|
|
|
using namespace facebook;
|
|
|
|
/**
|
|
* Allows caching `jsi::PropNameID`s via `std::string`s.
|
|
* The returned `jsi::PropNameID` can be used for JSI operations like
|
|
* - `jsi::Object::getProperty(...)`
|
|
* - `jsi::Object::setProperty(...)`
|
|
* - `jsi::Object::hasProperty(...)`
|
|
* And is more efficient than the string equivalent overloads of those
|
|
* functions due to caching.
|
|
*/
|
|
class PropNameIDCache final {
|
|
public:
|
|
PropNameIDCache() = delete;
|
|
~PropNameIDCache() = delete;
|
|
|
|
/**
|
|
* Get a `jsi::PropNameID` for the given `std::string` value.
|
|
* The `jsi::PropNameID` is only valid within the callee's current
|
|
* synchronous scope, and must be non-escaping.
|
|
*/
|
|
static const jsi::PropNameID& get(jsi::Runtime& runtime, std::string value);
|
|
|
|
private:
|
|
using CacheMap = std::unordered_map<std::string, BorrowingReference<jsi::PropNameID>>;
|
|
static std::unordered_map<jsi::Runtime*, CacheMap> _cache;
|
|
};
|
|
|
|
} // namespace margelo::nitro
|