Commit 872f8ab
authored
[refactor] Apply forward declaration as much as possible (apache#64)
* [refactor] Apply forward declaration as much as possible
Fixes apache#60
### Motivation
The includes in pulsar-client-cpp is very casual. There are a lot of
implicit includes and the forward declaration is not used much. For
example, if `lib/ClientConnection.h` was modified, 27 files would be
recompiled.
The other problem is the `SortIncludes` attribute in `.clang-format`
file is false. It might be okay in early days. However, as the project
grows, including many headers without ordering brings a very bad
experience. Combining with the very few usages of the forward
declaration, it's hard to determine whether a header is still required
after a change.
### Modifications
Apply forward declarations as much as possible and change the
`SortIncludes` to true in `.clang-format` file.
It's special for the `PulsarApi.pb.h` file because the size of this
header is over 1 MiB. For classes we can use forward declaration, but
for enumerations we have to include this header.
To solve this problem, `ProtoApiEnums.h` is added to define some
constant integers that can be cast implicitly from the enumerations. If
we want to use enumerations from `PulsarApi.pb.h`, we can include
`ProtoApiEnums.h` instead.
Finally, to unify the include rules, in `lib/*.h`, if we want to include
a header (e.g. `xxx.h`) from the same directory, just use `#include
"xxx.h"`. Don't use `#include "lib/xxx.h"` or `#include <lib/xxx.h>` in
headers of `lib/` directory.
### Improvements
Since forward declaration is applied everywhere now, take
`lib/ClientConnection.h` for example. After this patch, only 10 files
needs to be recompiled, while 27 files would be recompiled before.
This patch also reduces the binary size and speeds up the compilation
time.
Binary size:
- `libpulsar.a`: 319234696 (305 MiB) -> 286716564 (274 MiB)
- `libpulsar.so`: 110162496 (106 MiB) -> 102428456 (98 MiB)
Compilation time with the following commands:
```bash
cmake -B build -DBUILD_TESTS=OFF
cmake --build build -j8
```
* Fix MSVC build1 parent 7bb6402 commit 872f8ab
File tree
278 files changed
+1557
-1123
lines changed- examples
- include/pulsar
- c
- lib
- auth
- athenz
- checksum
- c
- lz4
- stats
- perf
- tests
- c
- wireshark
Some content is hidden
Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
278 files changed
+1557
-1123
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
19 | 19 | | |
20 | 20 | | |
21 | 21 | | |
22 | | - | |
| 22 | + | |
23 | 23 | | |
24 | 24 | | |
25 | 25 | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
16 | 16 | | |
17 | 17 | | |
18 | 18 | | |
| 19 | + | |
| 20 | + | |
19 | 21 | | |
20 | 22 | | |
21 | 23 | | |
22 | | - | |
23 | | - | |
24 | | - | |
| 24 | + | |
25 | 25 | | |
26 | 26 | | |
27 | 27 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
16 | 16 | | |
17 | 17 | | |
18 | 18 | | |
19 | | - | |
20 | | - | |
21 | 19 | | |
22 | 20 | | |
23 | | - | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
24 | 24 | | |
25 | 25 | | |
26 | 26 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
16 | 16 | | |
17 | 17 | | |
18 | 18 | | |
19 | | - | |
20 | | - | |
21 | 19 | | |
22 | 20 | | |
23 | | - | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
24 | 24 | | |
25 | 25 | | |
26 | 26 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
16 | 16 | | |
17 | 17 | | |
18 | 18 | | |
19 | | - | |
20 | | - | |
21 | 19 | | |
22 | 20 | | |
23 | | - | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
24 | 24 | | |
25 | 25 | | |
26 | 26 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
19 | 19 | | |
20 | 20 | | |
21 | 21 | | |
| 22 | + | |
22 | 23 | | |
23 | | - | |
24 | | - | |
| 24 | + | |
| 25 | + | |
25 | 26 | | |
26 | 27 | | |
27 | | - | |
28 | | - | |
| 28 | + | |
| 29 | + | |
29 | 30 | | |
30 | 31 | | |
31 | 32 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
20 | 20 | | |
21 | 21 | | |
22 | 22 | | |
| 23 | + | |
23 | 24 | | |
24 | 25 | | |
25 | 26 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
19 | 19 | | |
20 | 20 | | |
21 | 21 | | |
22 | | - | |
23 | | - | |
24 | | - | |
| 22 | + | |
25 | 23 | | |
| 24 | + | |
| 25 | + | |
26 | 26 | | |
| 27 | + | |
27 | 28 | | |
28 | | - | |
29 | 29 | | |
30 | 30 | | |
31 | 31 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
19 | 19 | | |
20 | 20 | | |
21 | 21 | | |
22 | | - | |
| 22 | + | |
| 23 | + | |
23 | 24 | | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
24 | 28 | | |
25 | 29 | | |
26 | 30 | | |
27 | | - | |
28 | | - | |
29 | | - | |
30 | 31 | | |
31 | | - | |
32 | | - | |
| 32 | + | |
| 33 | + | |
33 | 34 | | |
34 | 35 | | |
35 | 36 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
19 | 19 | | |
20 | 20 | | |
21 | 21 | | |
22 | | - | |
23 | 22 | | |
24 | 23 | | |
| 24 | + | |
25 | 25 | | |
26 | 26 | | |
27 | 27 | | |
| |||
0 commit comments