Skip to content

Commit e15e62b

Browse files
committed
Remove uses of new/delete
1 parent 740ca4f commit e15e62b

File tree

1 file changed

+9
-6
lines changed

1 file changed

+9
-6
lines changed

icu4c/source/i18n/messageformat2.cpp

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -182,9 +182,10 @@ FunctionContext MessageFormatter::makeFunctionContext(const FunctionOptions& opt
182182
} else {
183183
UErrorCode localStatus = U_ZERO_ERROR;
184184
int32_t len = localeStr.length();
185-
LocalArray<char> temp(new char[len + 1]);
186-
localeStr.extract(0, len, temp.getAlias(), len);
187-
Locale l = Locale::forLanguageTag(StringPiece(temp.getAlias(), len), localStatus);
185+
char* buf = static_cast<char*>(uprv_malloc(len + 1));
186+
localeStr.extract(0, len, buf, len);
187+
Locale l = Locale::forLanguageTag(StringPiece(buf, len), localStatus);
188+
uprv_free(buf);
188189
if (U_SUCCESS(localStatus)) {
189190
localeToUse = l;
190191
} else {
@@ -422,18 +423,18 @@ void MessageFormatter::matchSelectorKeys(const UVector& keys,
422423
LocalArray<UnicodeString> adoptedKeys(keysArr);
423424

424425
// Create an array to hold the output
425-
int32_t* prefsArr = new int32_t[keysLen];
426+
int32_t* prefsArr = static_cast<int32_t*>(uprv_malloc(keysLen * sizeof(int32_t)));
426427
if (prefsArr == nullptr) {
427428
status = U_MEMORY_ALLOCATION_ERROR;
428429
return;
429430
}
430-
LocalArray<int32_t> adoptedPrefs(prefsArr);
431+
431432
int32_t prefsLen = 0;
432433

433434
// Call the selector
434435
// Already checked for fallback, so it's safe to call takeValue()
435436
LocalPointer<FunctionValue> rvVal(rv.takeValue(status));
436-
rvVal->selectKeys(adoptedKeys.getAlias(), keysLen, adoptedPrefs.getAlias(), prefsLen,
437+
rvVal->selectKeys(adoptedKeys.getAlias(), keysLen, prefsArr, prefsLen,
437438
status);
438439

439440
// Update errors
@@ -461,6 +462,8 @@ void MessageFormatter::matchSelectorKeys(const UVector& keys,
461462
keysOut.adoptElement(k, status);
462463
CHECK_ERROR(status);
463464
}
465+
466+
uprv_free(prefsArr);
464467
}
465468

466469
// See https://github.com/unicode-org/message-format-wg/blob/main/spec/formatting.md#resolve-preferences

0 commit comments

Comments
 (0)