Skip to content

Commit

Permalink
Make buffer for converting decimal128 to string thread local
Browse files Browse the repository at this point in the history
  • Loading branch information
nielsenko committed Jan 23, 2024
1 parent 4975471 commit 78eada7
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions src/realm_dart_decimal128.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,13 @@ RLM_API realm_decimal128_t realm_dart_decimal128_from_string(const char* string)
return to_decimal128(result);
}

// This buffer is reused between calls, hence it is thread local
thread_local char _decimal128_to_string_buffer[34];
RLM_API realm_string_t realm_dart_decimal128_to_string(realm_decimal128_t x) {
auto x_bid = to_BID_UINT128(x);
// This buffer is reused between calls, hence the static keyword
static char buffer[34]; // 34 bytes is the maximum length of a string representation of a decimal128
unsigned int flags = 0;
bid128_to_string(buffer, &x_bid, &flags);
return realm_string_t{ buffer, strlen(buffer) };
bid128_to_string(_decimal128_to_string_buffer, &x_bid, &flags);
return realm_string_t{ _decimal128_to_string_buffer, strlen(_decimal128_to_string_buffer) };
}

RLM_API realm_decimal128_t realm_dart_decimal128_nan() {
Expand Down

0 comments on commit 78eada7

Please sign in to comment.