{
Contract.Assert(s != null);
- char[] buf = new char[s.Length];
+ if (s.Length == 0)
+ {
+ return string.Empty;
+ }
- fixed(char* pBuf = buf)
+ string result = string.FastAllocateString(s.Length);
+ fixed (char* pBuf = result)
{
- Interop.GlobalizationInterop.ChangeCase(s, s.Length, pBuf, buf.Length, toUpper, m_needsTurkishCasing);
+ Interop.GlobalizationInterop.ChangeCase(s, s.Length, pBuf, result.Length, toUpper, m_needsTurkishCasing);
}
- return new string(buf);
+ return result;
}
[System.Security.SecuritySafeCritical]
private unsafe char ChangeCase(char c, bool toUpper)
{
- char* pSrc = stackalloc char[1];
- char* pDst = stackalloc char[1];
-
- pSrc[0] = c;
+ char dst = default(char);
- Interop.GlobalizationInterop.ChangeCase(pSrc, 1, pDst, 1, toUpper, m_needsTurkishCasing);
+ Interop.GlobalizationInterop.ChangeCase(&c, 1, &dst, 1, toUpper, m_needsTurkishCasing);
- return pDst[0];
+ return dst;
}
// -----------------------------