pitrou commented on a change in pull request #11013:
URL: https://github.com/apache/arrow/pull/11013#discussion_r697315295
##########
File path: cpp/src/arrow/util/utf8.cc
##########
@@ -84,11 +85,9 @@ ARROW_EXPORT void CheckUTF8Initialized() {
} // namespace internal
-static std::once_flag utf8_initialized;
+void InitializeUTF8() {}
-void InitializeUTF8() {
- std::call_once(utf8_initialized, internal::InitializeLargeTable);
-}
+ARROW_INITIALIZER({ internal::InitializeLargeTable(); });
Review comment:
Sounds good.
As a sidenote, I wonder if the large table can be initialized at
compile-time by using a `constexpr` initialization function. Perhaps C++11 is
not potent enough?
```c++
constexpr const std::array<uint8_t> utf8_small_table = { ... };
static constexpr std::array<uint16_t, 9 * 256> InitializeLargeTable() = {
std::array<uint16_t, 9 * 256> utf8_large_table;
for (uint32_t state = 0; state < 9; ++state) {
for (uint32_t byte = 0; byte < 256; ++byte) {
uint32_t byte_class = utf8_small_table[byte];
uint8_t next_state = utf8_small_table[256 + state * 12 + byte_class] /
12;
DCHECK_LT(next_state, 9);
utf8_large_table[state * 256 + byte] =
static_cast<uint16_t>(next_state * 256);
}
}
return utf8_large_table;
}
constexpr const auto utf8_large_table = InitializeLargeTable();
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]