mirror of
https://github.com/unicode-org/icu.git
synced 2025-04-14 17:24:01 +00:00
ICU-13725 Fixing NumberFormatter std::move test failure on MSVC.
X-SVN-Rev: 41282
This commit is contained in:
parent
e77603e3c3
commit
c13e7785c2
2 changed files with 31 additions and 13 deletions
|
@ -378,13 +378,11 @@ LocalizedNumberFormatter::LocalizedNumberFormatter(LocalizedNumberFormatter&& sr
|
|||
|
||||
LocalizedNumberFormatter::LocalizedNumberFormatter(NFS<LNF>&& src) U_NOEXCEPT
|
||||
: NFS<LNF>(std::move(src)) {
|
||||
// For the move operators, copy over the call count and compiled formatter.
|
||||
auto&& srcAsLNF = static_cast<LNF&&>(src);
|
||||
fCompiled = srcAsLNF.fCompiled;
|
||||
uprv_memcpy(fUnsafeCallCount, srcAsLNF.fUnsafeCallCount, sizeof(fUnsafeCallCount));
|
||||
// Reset the source object to leave it in a safe state.
|
||||
srcAsLNF.fCompiled = nullptr;
|
||||
uprv_memset(srcAsLNF.fUnsafeCallCount, 0, sizeof(fUnsafeCallCount));
|
||||
// For the move operators, copy over the compiled formatter.
|
||||
// Note: if the formatter is not compiled, call count information is lost.
|
||||
if (static_cast<LNF&&>(src).fCompiled != nullptr) {
|
||||
lnfMoveHelper(static_cast<LNF&&>(src));
|
||||
}
|
||||
}
|
||||
|
||||
LocalizedNumberFormatter& LocalizedNumberFormatter::operator=(const LNF& other) {
|
||||
|
@ -395,15 +393,33 @@ LocalizedNumberFormatter& LocalizedNumberFormatter::operator=(const LNF& other)
|
|||
|
||||
LocalizedNumberFormatter& LocalizedNumberFormatter::operator=(LNF&& src) U_NOEXCEPT {
|
||||
NFS<LNF>::operator=(static_cast<NFS<LNF>&&>(src));
|
||||
// For the move operators, copy over the call count and compiled formatter.
|
||||
fCompiled = src.fCompiled;
|
||||
uprv_memcpy(fUnsafeCallCount, src.fUnsafeCallCount, sizeof(fUnsafeCallCount));
|
||||
// Reset the source object to leave it in a safe state.
|
||||
src.fCompiled = nullptr;
|
||||
uprv_memset(src.fUnsafeCallCount, 0, sizeof(fUnsafeCallCount));
|
||||
// For the move operators, copy over the compiled formatter.
|
||||
// Note: if the formatter is not compiled, call count information is lost.
|
||||
if (static_cast<LNF&&>(src).fCompiled != nullptr) {
|
||||
// Formatter is compiled
|
||||
lnfMoveHelper(static_cast<LNF&&>(src));
|
||||
} else {
|
||||
// Reset to default values.
|
||||
auto* callCount = reinterpret_cast<u_atomic_int32_t*>(fUnsafeCallCount);
|
||||
umtx_storeRelease(*callCount, 0);
|
||||
fCompiled = nullptr;
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
|
||||
void LocalizedNumberFormatter::lnfMoveHelper(LNF&& src) {
|
||||
// Copy over the compiled formatter and set call count to INT32_MIN as in computeCompiled().
|
||||
// Don't copy the call count directly because doing so requires a loadAcquire/storeRelease.
|
||||
// The bits themselves appear to be platform-dependent, so copying them might not be safe.
|
||||
auto* callCount = reinterpret_cast<u_atomic_int32_t*>(fUnsafeCallCount);
|
||||
umtx_storeRelease(*callCount, INT32_MIN);
|
||||
fCompiled = src.fCompiled;
|
||||
// Reset the source object to leave it in a safe state.
|
||||
auto* srcCallCount = reinterpret_cast<u_atomic_int32_t*>(src.fUnsafeCallCount);
|
||||
umtx_storeRelease(*srcCallCount, 0);
|
||||
src.fCompiled = nullptr;
|
||||
}
|
||||
|
||||
|
||||
LocalizedNumberFormatter::~LocalizedNumberFormatter() {
|
||||
delete fCompiled;
|
||||
|
|
|
@ -2293,6 +2293,8 @@ class U_I18N_API LocalizedNumberFormatter
|
|||
|
||||
LocalizedNumberFormatter(impl::MacroProps &¯os, const Locale &locale);
|
||||
|
||||
void lnfMoveHelper(LocalizedNumberFormatter&& src);
|
||||
|
||||
/**
|
||||
* @return true if the compiled formatter is available.
|
||||
*/
|
||||
|
|
Loading…
Add table
Reference in a new issue