Skip to content

Commit 2f78a41

Browse files
Fix Bugzilla Issue 10560 - to!string creates unnecessary allocation for structs with toString
1 parent 3f990a7 commit 2f78a41

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

std/conv.d

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1013,7 +1013,17 @@ if (!(is(S : T) &&
10131013
!isEnumStrToStr!(S, T) && !isNullToStr!(S, T)) &&
10141014
!isInfinite!S && isExactSomeString!T)
10151015
{
1016-
static if (isExactSomeString!S && value[0].sizeof == ElementEncodingType!T.sizeof)
1016+
static if (is(typeof(T.init.toString())) && __traits(compiles, T.init.toString()) &&
1017+
isSomeString!(typeof(T.init.toString())))
1018+
{
1019+
1020+
auto toImpl(T value)
1021+
{
1022+
return value.toString();
1023+
}
1024+
}
1025+
1026+
else static if (isExactSomeString!S && value[0].sizeof == ElementEncodingType!T.sizeof)
10171027
{
10181028
// string-to-string with incompatible qualifier conversion
10191029
static if (is(ElementEncodingType!T == immutable))

0 commit comments

Comments
 (0)