Skip to content

Commit 53aa2be

Browse files
authored
Merge pull request #5129 from JackStouffer/singleSpec
Remove unnessesary GC allocations in std.format.singleSpec
2 parents 2395725 + 8424b57 commit 53aa2be

File tree

1 file changed

+6
-5
lines changed

1 file changed

+6
-5
lines changed

std/format.d

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1255,14 +1255,15 @@ Params:
12551255
12561256
Returns:
12571257
A $(D FormatSpec) with the specifier parsed.
1258-
1259-
Enforces giving only one specifier to the function.
1258+
Throws:
1259+
An `Exception` when more than one specifier is given or the specifier
1260+
is malformed.
12601261
*/
12611262
FormatSpec!Char singleSpec(Char)(Char[] fmt)
12621263
{
12631264
import std.conv : text;
1264-
enforce(fmt.length >= 2, new Exception("fmt must be at least 2 characters long"));
1265-
enforce(fmt.front == '%', new Exception("fmt must start with a '%' character"));
1265+
enforce(fmt.length >= 2, "fmt must be at least 2 characters long");
1266+
enforce(fmt.front == '%', "fmt must start with a '%' character");
12661267

12671268
static struct DummyOutputRange {
12681269
void put(C)(C[] buf) {} // eat elements
@@ -1273,7 +1274,7 @@ FormatSpec!Char singleSpec(Char)(Char[] fmt)
12731274
spec.writeUpToNextSpec(a);
12741275

12751276
enforce(spec.trailing.empty,
1276-
new Exception(text("Trailing characters in fmt string: '", spec.trailing)));
1277+
text("Trailing characters in fmt string: '", spec.trailing));
12771278

12781279
return spec;
12791280
}

0 commit comments

Comments
 (0)