Clean up after making formating floating point numbers @nogc.

This commit is contained in:
berni44 2021-04-24 14:08:50 +02:00 committed by The Dlang Bot
parent afc2df6ef2
commit 3206e52aae
4 changed files with 976 additions and 1023 deletions

View file

@ -0,0 +1,8 @@
Floating point numbers don't allocate with the GC anymore.
The implementation of formatting floating point numbers has been
reworked. We made sure that working examples never allocate with the
GC, however, we are still using exceptions which are GC managed.
Therefore, code that uses formatting correctly will never allocate,
but in the case of exceptions, the GC will be used to allocate the
exception. We are working on DIP 1008 to solve this issue.

File diff suppressed because it is too large Load diff

View file

@ -506,9 +506,7 @@ if (is(FloatingPointTypeOf!T) && !is(T == enum) && !hasToString!(T, Char))
} }
fs.spec = spec2; fs.spec = spec2;
buf = printFloat(buf2[], w, val, fs, mode); printFloat(w, val, fs, mode);
len = buf.length;
if (len == 0) return;
} }
else else
{ {
@ -561,7 +559,6 @@ if (is(FloatingPointTypeOf!T) && !is(T == enum) && !hasToString!(T, Char))
len = min(n, buf2.length-1); len = min(n, buf2.length-1);
buf = buf2; buf = buf2;
}
if (fs.flSeparator && !inf && !nan) if (fs.flSeparator && !inf && !nan)
{ {
@ -644,6 +641,7 @@ if (is(FloatingPointTypeOf!T) && !is(T == enum) && !hasToString!(T, Char))
put(w, buf[0 .. len]); put(w, buf[0 .. len]);
} }
} }
}
@safe unittest @safe unittest
{ {

View file

@ -1511,8 +1511,6 @@ Note:
$(UL $(UL
$(LI An exception is thrown.) $(LI An exception is thrown.)
$(LI A floating point number of type `real` is formatted.)
$(LI The representation of a floating point number exceeds 500 characters.)
$(LI A custom `toString` function of a compound type allocates.)) $(LI A custom `toString` function of a compound type allocates.))
*/ */
char[] sformat(Char, Args...)(return scope char[] buf, scope const(Char)[] fmt, Args args) char[] sformat(Char, Args...)(return scope char[] buf, scope const(Char)[] fmt, Args args)