mirror of
https://github.com/zoriya/nitro.git
synced 2026-10-13 00:05:23 +00:00
* feat: Create `HybridView` Swift and Kotlin base
* fix: HybridView
* feat: Add `HybridView.ts` to nitrogen
* feat: Add necessary changes to nitrogen
* fix: Actually resolve type to find base types (HybridView -> HybridObject)
* feat: Generate TestView.nitro.ts 🎉
* fix: Fix hybrid view base accidentally
* fix: Pass `HybridData` to super
* fix: Finally fix `HybridView` recursion
* fix: Make `HybridView` the protocol's base instead
* Always inherit HybridObject
* run nitrogen
* feat: Create props file
* Name it component
* fix: Indent
* Add warn for RN 78 requirement
* move into `views`
* Create `.mm` file as well
* Add super.load
* fix: Fix namespace
* fix: indent
* fix it?
* Update NitroDefines.hpp
* fix: Make `/views/` private header
* Add filter func and some docs
* feat: More docs
* sort
* feat: Also create Android part
* feat: Implement actual prop parsing
* ah fix
* fix: Runtime type
* fix: Add `hashString(string_view)` equivalent
* fix: Add string_view and string overloads
* fix: indent shadownode
* whoops
* fix: Wrap in state
* comments
* fix: Fix throw when RN isnt present
* fix: Fix `Any?` type
* fix: Includes
* feat: Autolink it and implement it..?
* fix: Load native part of `NitroImage` in shared OnLoad.kt file
* fix: Actually add view-manager to Package
* fix: Rename to Hybrid* prefix
* fix: Use the `*OnLoad` init func now
* fix: Remove duplicate JNI registrations
61 lines
1.4 KiB
C++
61 lines
1.4 KiB
C++
//
|
|
// NitroHash.hpp
|
|
// react-native-nitro
|
|
//
|
|
// Created by Marc Rousavy on 14.07.24.
|
|
//
|
|
|
|
#pragma once
|
|
|
|
#include <cstddef>
|
|
#include <cstdint>
|
|
#include <string>
|
|
|
|
namespace margelo::nitro {
|
|
|
|
/**
|
|
* Hashes the given C-String using the FNV-1a hashing algorithm.
|
|
*
|
|
* This function can be used at compile time as a constexpr to build
|
|
* statically optimized switch statements.
|
|
*/
|
|
constexpr uint64_t hashString(const char* str, size_t length) {
|
|
uint64_t hash = 14695981039346656037ull; // FNV offset basis
|
|
const uint64_t fnv_prime = 1099511628211ull;
|
|
|
|
for (size_t i = 0; i < length; ++i) {
|
|
hash ^= static_cast<uint64_t>(str[i]);
|
|
hash *= fnv_prime;
|
|
}
|
|
|
|
return hash;
|
|
}
|
|
|
|
/**
|
|
* Hashes the given constant C-String using the FNV-1a hashing algorithm.
|
|
*
|
|
* String length is known at compile time.
|
|
*/
|
|
template <size_t N>
|
|
constexpr uint64_t hashString(const char (&str)[N]) {
|
|
return hashString(str, N - 1); // N includes the null terminator, so subtract 1
|
|
}
|
|
|
|
/**
|
|
* Hashes the given `string_view` using the FNV-1a hashing algorithm.
|
|
* This can be constexpr.
|
|
*/
|
|
constexpr uint64_t hashString(const std::string_view& string) {
|
|
return hashString(string.data(), string.length());
|
|
}
|
|
|
|
/**
|
|
* Hashes the given `string` using the FNV-1a hashing algorithm.
|
|
* This happens at runtime.
|
|
*/
|
|
inline uint64_t hashString(const std::string& string) {
|
|
return hashString(string.c_str(), string.length());
|
|
}
|
|
|
|
} // namespace margelo::nitro
|