From f56fd7580ce74395aed7d448c490f33328884913 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=B6nke=20Ludwig?= Date: Tue, 22 Oct 2019 11:41:35 +0200 Subject: [PATCH] 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. --- source/vibe/core/file.d | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/source/vibe/core/file.d b/source/vibe/core/file.d index 410ddf3..db2a1ea 100644 --- a/source/vibe/core/file.d +++ b/source/vibe/core/file.d @@ -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)