… | |
… | |
2 | #define DYNBUF_H__ |
2 | #define DYNBUF_H__ |
3 | |
3 | |
4 | #include <cstring> |
4 | #include <cstring> |
5 | #include <cassert> |
5 | #include <cassert> |
6 | |
6 | |
|
|
7 | #include "util.h" |
7 | #include "shstr.h" |
8 | #include "shstr.h" |
8 | |
9 | |
9 | // this is a "buffer" that can grow fast |
10 | // this is a "buffer" that can grow fast |
10 | // and is still somewhat space-efficient. |
11 | // and is still somewhat space-efficient. |
11 | // unlike obstacks or other data structures, |
12 | // unlike obstacks or other data structures, |
… | |
… | |
47 | |
48 | |
48 | int room () const { return end - ptr; } |
49 | int room () const { return end - ptr; } |
49 | |
50 | |
50 | char *force (int size) |
51 | char *force (int size) |
51 | { |
52 | { |
52 | if (ptr + size >= end) |
53 | if (expect_false (ptr + size >= end)) |
53 | _reserve (size); |
54 | _reserve (size); |
54 | |
55 | |
55 | return ptr; |
56 | return ptr; |
56 | } |
57 | } |
57 | |
58 | |