зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1412416 - Part 1: Support arena duplication of wide strings. r=froydnj
This adds support for duplicating both raw `char*` strings and raw `char16_t*` strings by making the character type generic. --HG-- extra : rebase_source : bb5245ed71161c8c785684e5a56ac894f03874ea extra : histedit_source : e94eb738a3982f0cb63a894a0cdfbdf0be2b9cad
This commit is contained in:
Родитель
316ad3a257
Коммит
1a39968857
|
@ -32,11 +32,11 @@ T* DuplicateString(const T* aSrc, const CheckedInt<size_t>& aLen,
|
|||
* @param aArena The arena to allocate the string copy out of.
|
||||
* @return An arena allocated null-terminated string.
|
||||
*/
|
||||
template<size_t ArenaSize, size_t Alignment>
|
||||
char* ArenaStrdup(const char* aStr,
|
||||
ArenaAllocator<ArenaSize, Alignment>& aArena)
|
||||
template<typename T, size_t ArenaSize, size_t Alignment>
|
||||
T* ArenaStrdup(const T* aStr,
|
||||
ArenaAllocator<ArenaSize, Alignment>& aArena)
|
||||
{
|
||||
return detail::DuplicateString(aStr, strlen(aStr), aArena);
|
||||
return detail::DuplicateString(aStr, nsCharTraits<T>::length(aStr), aArena);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -284,10 +284,15 @@ TEST(ArenaAllocator, Clear)
|
|||
TEST(ArenaAllocator, Extensions)
|
||||
{
|
||||
ArenaAllocator<4096, 8> a;
|
||||
const char* const kTestStr = "This is a test string.";
|
||||
char* dup = mozilla::ArenaStrdup(kTestStr, a);
|
||||
EXPECT_STREQ(dup, kTestStr);
|
||||
|
||||
// Test with raw strings.
|
||||
const char* const kTestCStr = "This is a test string.";
|
||||
char* c_dup = mozilla::ArenaStrdup(kTestCStr, a);
|
||||
EXPECT_STREQ(c_dup, kTestCStr);
|
||||
|
||||
const char16_t* const kTestStr = u"This is a wide test string.";
|
||||
char16_t* dup = mozilla::ArenaStrdup(kTestStr, a);
|
||||
EXPECT_TRUE(nsString(dup).Equals(kTestStr));
|
||||
NS_NAMED_LITERAL_STRING(wideStr, "A wide string.");
|
||||
nsLiteralString::char_type* wide = mozilla::ArenaStrdup(wideStr, a);
|
||||
EXPECT_TRUE(wideStr.Equals(wide));
|
||||
|
|
Загрузка…
Ссылка в новой задаче