[sil-combine] String literal concatenation optimization. Constant-fold concatenation of string literals known at compile-time.

Addresses rdar://17033696.

Swift SVN r21526
This commit is contained in:
Roman Levenstein
2014-08-28 11:33:21 +00:00
parent ea0676147c
commit 97014172b7
11 changed files with 760 additions and 13 deletions

View File

@@ -94,3 +94,19 @@ unsigned swift::unicode::extractFirstUnicodeScalar(StringRef S) {
return Scalar;
}
uint64_t swift::unicode::getUTF16Length(StringRef Str) {
uint64_t Length;
// Transcode the string to UTF-16 to get its length.
SmallVector<UTF16, 128> buffer(Str.size() + 1); // +1 for ending nulls.
const UTF8 *fromPtr = (const UTF8 *) Str.data();
UTF16 *toPtr = &buffer[0];
ConversionResult Result = ConvertUTF8toUTF16(&fromPtr, fromPtr + Str.size(),
&toPtr, toPtr + Str.size(),
strictConversion);
assert(Result == conversionOK &&
"UTF-8 encoded string cannot be converted into UTF-16 encoding");
// The length of the transcoded string in UTF-16 code points.
Length = toPtr - &buffer[0];
return Length;
}