Skip to content

Commit

Permalink
Fix string key issue with constexpr StrKey in Performance C++ native …
Browse files Browse the repository at this point in the history
…module

Summary:
I encountered build error when using performance API in catalyst android mobile app. The error message P617433618 points at using non-const `std::strlen` API in a `constexpr`.

```
$ buck install catalyst-android
...
stderr: xplat/js/react-native-github/Libraries/WebPerformance/PerformanceEntryReporter.cpp:208:13: error: constexpr constructor never produces a constant expression [-Winvalid-constexpr]
  constexpr StrKey(const char *s)
            ^
xplat/js/react-native-github/Libraries/WebPerformance/PerformanceEntryReporter.cpp:209:39: note: non-constexpr function 'strlen' cannot be used in a constant expression
      : key(folly::hash::fnv32_buf(s, std::strlen(s))) {}
```

Changelog:
[General][Fixed] - Fixed string key calculation in constexpr from Performance C++ native module.

Reviewed By: javache

Differential Revision: D43136624

fbshipit-source-id: c691671b157b507745c67a505c91f75cf6b878d1
  • Loading branch information
Xin Chen authored and facebook-github-bot committed Feb 9, 2023
1 parent d6e9891 commit 6faddc3
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion Libraries/WebPerformance/PerformanceEntryReporter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ void PerformanceEntryReporter::scheduleFlushBuffer() {
struct StrKey {
uint32_t key;
constexpr StrKey(const char *s)
: key(folly::hash::fnv32_buf(s, std::strlen(s))) {}
: key(folly::hash::fnv32_buf(s, sizeof(s) - 1)) {}

constexpr bool operator==(const StrKey &rhs) const {
return key == rhs.key;
Expand Down

0 comments on commit 6faddc3

Please sign in to comment.