The commits in this pull request implement a sequence of changes:
- Simplifications:
- Remove unused ReadVersion and WriteVersion CDataStream and CAutoFile had a ReadVersion and WriteVersion method that was never used. Remove them.
- Make nType and nVersion private and sometimes const Make the various stream implementations’ nType and nVersion private and const (except in CDataStream where we really need a setter).
- Make streams’ read and write return void The stream implementations have two layers (the upper one with operator« and operator», and a lower one with read and write). The lower layer’s return values are never used (nor should they, as they should only be used from the higher layer), so make them void.
- Make GetSerializeSize a wrapper on top of CSizeComputer Given that in default GetSerializeSize implementations we’re already using CSizeComputer(), get rid of the specialized GetSerializeSize methods everywhere, and just use CSizeComputer. This removes a lot of code which isn’t actually used anywhere. In a few places, this removes an actually more efficient size computing algorithm, which we’ll bring back in the “Add optimized CSizeComputer serializers” commit later.
- Get rid of nType and nVersion The big change: remove the nType and nVersion as parameters to all serialization methods and functions. There is only one place where it’s read and has an impact (in CAddress), and even there it does not impact any of the member objects’ serializations. Instead, the few places that need nType or nVersion read it directly from the stream, through GetType and GetVersion calls which are added to all streams.
- Avoid -Wshadow errors As suggested by @paveljanik, remove the few remaining cases of variable shadowing in the serialization code.
- Optimizations:
- Make CSerAction’s ForRead() constexpr The CSerAction’s ForRead() method does not depend on any runtime data, so guarantee that requests to it can be optimized out by making it constexpr (suggested by @theuni in #8580).
- Add optimized CSizeComputer serializers To get the advantages of faster GetSerializeSize implementations back, reintroduce them in the few places where they actually make a difference, in the form of a specialized Serialize implementation. This actually gets us in a better state than before, as these even get used when they’re nested inside the serialization of another object.
- Use fixed preallocation instead of costly GetSerializeSize dbwrapper uses GetSerializeSize to compute the size of the buffer to preallocate. For some cases (specifically: CCoins) this requires a costly compression call. Avoid this by just using fixed size preallocations instead.
This will make it easier to address @TheBlueMatt’s comments in #8580, resulting is a simpler and more efficient way to simultaneously deserialize+construct objects with const members from streams.
I assume this conflicts/supersedes #8468.