Avoid reallocating the data in readFileUTF8 if the UTF encoding is valid.

Uses the immutable overload of sanitizeUTF8 to reuse the original buffer if possible.
This commit is contained in:
Sönke Ludwig 2019-10-22 11:41:35 +02:00
parent 2e4bc6a316
commit f56fd7580c

View file

@ -118,7 +118,9 @@ string readFileUTF8(NativePath path)
{
import vibe.internal.string;
return stripUTF8Bom(sanitizeUTF8(readFile(path)));
auto data = readFile(path);
auto idata = () @trusted { return data.assumeUnique; } ();
return stripUTF8Bom(sanitizeUTF8(idata));
}
/// ditto
string readFileUTF8(string path)