Backed out changeset 26c080929f59 (bug 1318403)

This commit is contained in:
Sebastian Hengst 2017-04-06 15:23:04 +02:00
Родитель 2da3a9cf8e
Коммит a8f466a40b
1 изменённых файлов: 34 добавлений и 36 удалений

Просмотреть файл

@ -1060,40 +1060,6 @@ CopyChars(CharT* destChars, const CharT* srcChars, size_t length)
PodCopy(destChars, srcChars, length);
}
template <typename DestChar, typename SrcChar>
static inline UniquePtr<DestChar[], JS::FreePolicy>
ToUpperCase(JSContext* cx, const SrcChar* chars, size_t startIndex, size_t length,
size_t* resultLength)
{
MOZ_ASSERT(startIndex < length);
using DestCharPtr = UniquePtr<DestChar[], JS::FreePolicy>;
*resultLength = length;
DestCharPtr buf = cx->make_pod_array<DestChar>(length + 1);
if (!buf)
return buf;
CopyChars(buf.get(), chars, startIndex);
size_t readChars = ToUpperCaseImpl(buf.get(), chars, startIndex, length, length);
if (readChars < length) {
size_t actualLength = ToUpperCaseLength(chars, readChars, length);
*resultLength = actualLength;
DestCharPtr buf2 = ReallocChars(cx, Move(buf), length + 1, actualLength + 1);
if (!buf2)
return buf2;
buf = Move(buf2);
MOZ_ALWAYS_TRUE(length ==
ToUpperCaseImpl(buf.get(), chars, readChars, length, actualLength));
}
return buf;
}
template <typename CharT>
static JSString*
ToUpperCase(JSContext* cx, JSLinearString* str)
@ -1165,16 +1131,48 @@ ToUpperCase(JSContext* cx, JSLinearString* str)
}
if (resultIsLatin1) {
Latin1CharPtr buf = ToUpperCase<Latin1Char>(cx, chars, i, length, &resultLength);
resultLength = length;
Latin1CharPtr buf = cx->make_pod_array<Latin1Char>(resultLength + 1);
if (!buf)
return nullptr;
CopyChars(buf.get(), chars, i);
size_t readChars = ToUpperCaseImpl(buf.get(), chars, i, length, resultLength);
if (readChars < length) {
resultLength = ToUpperCaseLength(chars, readChars, length);
Latin1CharPtr buf2 = ReallocChars(cx, Move(buf), length + 1, resultLength + 1);
if (!buf2)
return nullptr;
buf = Move(buf2);
MOZ_ALWAYS_TRUE(length ==
ToUpperCaseImpl(buf.get(), chars, readChars, length, resultLength));
}
newChars.construct<Latin1CharPtr>(Move(buf));
} else {
TwoByteCharPtr buf = ToUpperCase<char16_t>(cx, chars, i, length, &resultLength);
resultLength = length;
TwoByteCharPtr buf = cx->make_pod_array<char16_t>(resultLength + 1);
if (!buf)
return nullptr;
CopyChars(buf.get(), chars, i);
size_t readChars = ToUpperCaseImpl(buf.get(), chars, i, length, resultLength);
if (readChars < length) {
resultLength = ToUpperCaseLength(chars, readChars, length);
TwoByteCharPtr buf2 = ReallocChars(cx, Move(buf), length + 1, resultLength + 1);
if (!buf2)
return nullptr;
buf = Move(buf2);
MOZ_ALWAYS_TRUE(length ==
ToUpperCaseImpl(buf.get(), chars, readChars, length, resultLength));
}
newChars.construct<TwoByteCharPtr>(Move(buf));
}
}