Skip to content

Commit 2694be8

Browse files
committed
feat: enhance write performance
1 parent f6a8373 commit 2694be8

1 file changed

Lines changed: 7 additions & 5 deletions

File tree

src/alfred/config/fast-io.hpp

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -94,15 +94,17 @@ inline void fast_read(std::string &s) {
9494

9595
template <class T>
9696
inline void write(T x) {
97-
int cnt = 0;
98-
static char buf[40];
97+
bool neg = false;
9998
if (x < 0) {
100-
buf[cnt++] = '-', x = -x;
99+
neg = true, x = -x;
101100
}
101+
int it = 40;
102+
static char buf[40];
102103
do {
103-
buf[cnt++] = (x % 10) ^ 48, x /= 10;
104+
buf[--it] = (x % 10) ^ 48, x /= 10;
104105
} while (x);
105-
while (cnt--) __buf.pc(buf[cnt]);
106+
if (neg) buf[--it] = '-';
107+
__buf.ps(buf + it, 40 - it);
106108
}
107109
template <int mod>
108110
inline void write(ModInt<mod> x) { write(x.x); }

0 commit comments

Comments
 (0)