Skip to content

Commit eb260a0

Browse files
committed
Enhanced fast-io.hpp
1 parent 7a6a9c2 commit eb260a0

1 file changed

Lines changed: 8 additions & 12 deletions

File tree

src/alfred/config/fast-io.hpp

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,10 @@
66

77
class FastIO {
88
private:
9-
int chunk = 1 << 18;
10-
char *buf, *p1, *p2;
11-
char *obuf, *op;
9+
char *buf, *p1, *p2, *obuf, *op;
10+
static const int chunk = 1 << 18;
1211

13-
inline void flush_output() {
14-
size_t len = size_t(op - obuf);
12+
inline void flush_output(int len = chunk) {
1513
fwrite(obuf, 1, len, stdout), op = obuf;
1614
}
1715

@@ -27,19 +25,17 @@ class FastIO {
2725
if (op == obuf + chunk) flush_output();
2826
*op++ = c;
2927
}
30-
FastIO(void) : chunk(1 << 18) {
31-
p1 = p2 = buf = (char *)(malloc(chunk));
32-
op = obuf = (char *)(malloc(chunk));
33-
}
34-
FastIO(int _chunk) : chunk(_chunk) {
28+
FastIO(void) {
3529
p1 = p2 = buf = (char *)(malloc(chunk));
3630
op = obuf = (char *)(malloc(chunk));
3731
}
3832
~FastIO(void) {
39-
flush_output();
33+
flush_output(op - obuf);
4034
free(buf), free(obuf);
4135
}
42-
inline void flush(void) { flush_output(); }
36+
inline void flush(void) {
37+
flush_output(op - obuf);
38+
}
4339
} __buf;
4440

4541
inline void pc(char c) { __buf.pc(c); }

0 commit comments

Comments
 (0)