Skip to content

Commit

Permalink
fix: Add hashString(string_view) equivalent
Browse files Browse the repository at this point in the history
  • Loading branch information
mrousavy committed Jan 15, 2025
1 parent 94b823d commit 7d56961
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 2 deletions.
2 changes: 1 addition & 1 deletion packages/nitrogen/src/views/ViewComponentShadowNode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ namespace ${namespace} {
}
bool ${propsClassName}::filterObjectKeys(const std::string& propName) {
switch (hashString(propName.c_str())) {
switch (hashString(propName)) {
${indent(cases.join('\n'), ' ')}
default: return false;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ namespace margelo::nitro::image::views {
}

bool HybridTestViewProps::filterObjectKeys(const std::string& propName) {
switch (hashString(propName.c_str())) {
switch (hashString(propName)) {
case hashString("someProp"): return true;
case hashString("someCallback"): return true;
default: return false;
Expand Down
5 changes: 5 additions & 0 deletions packages/react-native-nitro-modules/cpp/utils/NitroHash.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

#include <cstddef>
#include <cstdint>
#include <string>

namespace margelo::nitro {

Expand Down Expand Up @@ -40,4 +41,8 @@ constexpr uint64_t hashString(const char (&str)[N]) {
return hashString(str, N - 1); // N includes the null terminator, so subtract 1
}

inline uint64_t hashString(const std::string_view& string) {
return hashString(string.c_str(), string.length());
}

} // namespace margelo::nitro

0 comments on commit 7d56961

Please sign in to comment.