Skip to content

Commit cb63ee1

Browse files
committed
messages.d: avoid unnecessary idup when parsing strings
1 parent 22b220c commit cb63ee1

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

src/server/messages.d

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -209,11 +209,16 @@ class UMessage
209209
static if (is(T : string)) {
210210
if (size > 0) {
211211
const(ubyte)[] bytes = in_buf[offset .. offset + size];
212-
value = cast(T) bytes.idup; // UTF-8
213212
offset += size;
214213

215214
try {
216-
value.validate;
215+
@trusted
216+
static string decode_utf8(const(ubyte)[] bytes) {
217+
const value = cast(string) bytes;
218+
value.validate();
219+
return value;
220+
}
221+
value = decode_utf8(bytes);
217222
}
218223
catch (UTFException) {
219224
// Latin-1 fallback

0 commit comments

Comments
 (0)