Skip to content

Commit 24b9d02

Browse files
committed
Remove uses of new/delete
1 parent d3a3ca5 commit 24b9d02

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
@@ -227,9 +227,10 @@ FunctionContext MessageFormatter::makeFunctionContext(const FunctionOptions& opt
227227
} else {
228228
UErrorCode localStatus = U_ZERO_ERROR;
229229
int32_t len = localeStr.length();
230-
LocalArray<char> temp(new char[len + 1]);
231-
localeStr.extract(0, len, temp.getAlias(), len);
232-
Locale l = Locale::forLanguageTag(StringPiece(temp.getAlias(), len), localStatus);
230+
char* buf = static_cast<char*>(uprv_malloc(len + 1));
231+
localeStr.extract(0, len, buf, len);
232+
Locale l = Locale::forLanguageTag(StringPiece(buf, len), localStatus);
233+
uprv_free(buf);
233234
if (U_SUCCESS(localStatus)) {
234235
localeToUse = l;
235236
} else {
@@ -468,18 +469,18 @@ void MessageFormatter::matchSelectorKeys(const UVector& keys,
468469
LocalArray<UnicodeString> adoptedKeys(keysArr);
469470

470471
// Create an array to hold the output
471-
int32_t* prefsArr = new int32_t[keysLen];
472+
int32_t* prefsArr = static_cast<int32_t*>(uprv_malloc(keysLen * sizeof(int32_t)));
472473
if (prefsArr == nullptr) {
473474
status = U_MEMORY_ALLOCATION_ERROR;
474475
return;
475476
}
476-
LocalArray<int32_t> adoptedPrefs(prefsArr);
477+
477478
int32_t prefsLen = 0;
478479

479480
// Call the selector
480481
// Already checked for fallback, so it's safe to call takeValue()
481482
LocalPointer<FunctionValue> rvVal(rv.takeValue(status));
482-
rvVal->selectKeys(adoptedKeys.getAlias(), keysLen, adoptedPrefs.getAlias(), prefsLen,
483+
rvVal->selectKeys(adoptedKeys.getAlias(), keysLen, prefsArr, prefsLen,
483484
status);
484485

485486
// Update errors
@@ -507,6 +508,8 @@ void MessageFormatter::matchSelectorKeys(const UVector& keys,
507508
keysOut.adoptElement(k, status);
508509
CHECK_ERROR(status);
509510
}
511+
512+
uprv_free(prefsArr);
510513
}
511514

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

0 commit comments

Comments
 (0)