mirror of
https://github.com/ziglang/zig.git
synced 2024-11-27 23:52:31 +00:00
std.fmt.format: small optimization to avoid runtime bloat
When there are no format parameters, it simply calls `writeAll`. This has the effect of no longer emitting a compile error for using `{}` and not having any parameters, however, at this point in the development process of Zig I think that tradeoff is worthwhile. On the other hand, it might be OK to simply define formatting to work this way. It's a common pattern to use the formatting function's format string `"like this", .{}` instead of `"{}", .{"like this"}`, which can lead to accidentally putting control characters in the formatting string, however, with this change that works just fine.
This commit is contained in:
parent
4fdfaf69c8
commit
11d38a7e52
@ -88,6 +88,8 @@ pub fn format(
|
||||
if (args.len > ArgSetType.bit_count) {
|
||||
@compileError("32 arguments max are supported per format call");
|
||||
}
|
||||
if (args.len == 0)
|
||||
return writer.writeAll(fmt);
|
||||
|
||||
const State = enum {
|
||||
Start,
|
||||
|
Loading…
Reference in New Issue
Block a user