Originally written for #21590 (safegcd-based MuHash inverses), but then found a better way that removed the need for it, so I'm submitting it independently.
Generalize/simplify VectorReader into SpanReader #23653
pull sipa wants to merge 1 commits into bitcoin:master from sipa:202112_spanreader changing 8 files +35 −36-
sipa commented at 4:54 PM on December 2, 2021: member
- laanwj added the label Utils/log/libs on Dec 2, 2021
-
in src/blockfilter.cpp:84 in 06a1adf88d outdated
80 | @@ -81,7 +81,7 @@ GCSFilter::GCSFilter(const Params& params) 81 | GCSFilter::GCSFilter(const Params& params, std::vector<unsigned char> encoded_filter) 82 | : m_params(params), m_encoded(std::move(encoded_filter)) 83 | { 84 | - VectorReader stream(GCS_SER_TYPE, GCS_SER_VERSION, m_encoded, 0); 85 | + SpanReader stream(GCS_SER_TYPE, GCS_SER_VERSION, m_encoded, 0);
MarcoFalke commented at 6:36 PM on December 2, 2021:SpanReader stream{GCS_SER_TYPE, GCS_SER_VERSION, m_encoded, 0};nit: Haven't checked if it compiles.
sipa commented at 7:48 PM on December 2, 2021:Done, everywhere.
in src/streams.h:181 in 06a1adf88d outdated
176 | @@ -177,8 +177,8 @@ class VectorReader 177 | int GetVersion() const { return m_version; } 178 | int GetType() const { return m_type; } 179 | 180 | - size_t size() const { return m_data.size() - m_pos; } 181 | - bool empty() const { return m_data.size() == m_pos; } 182 | + size_t size() const { return m_data.size(); } 183 | + bool empty() const { return m_data.size() == 0; }
MarcoFalke commented at 6:38 PM on December 2, 2021:bool empty() const { return m_data.empty; }
sipa commented at 7:47 PM on December 2, 2021:Done.
MarcoFalke approvedMarcoFalke commented at 6:40 PM on December 2, 2021: memberACK 06a1adf88d51e2771802c6c0f646e3ff16a4baa7 💽
<details><summary>Show signature</summary>
Signature:
-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA512 ACK 06a1adf88d51e2771802c6c0f646e3ff16a4baa7 💽 -----BEGIN PGP SIGNATURE----- iQGzBAEBCgAdFiEE+rVPoUahrI9sLGYTzit1aX5ppUgFAlwqrYAACgkQzit1aX5p pUibXQwAg72RLZWg263rc7eMLWvExHZ+JJj91IV1IcqQqOd+BlGWIhtwih2/wy5J +fjp98EEgwYPy18TivkjGddaQqL+HCou9PWJNyUV0GPqgd2HDT+KNU9e1T6IDZsS 9+Ug+m/wsiY8tNLDOnZ6vJK+xFzu2oGQnNLOFxG4VFwh7fR20qvSitLU8Uhaz7et +9KBO2XAtHUAeYusDeTc6ZZHPErw/Pvd6p/qt3cBPtGSRMjNCSCUSGaDzXar415L AswOh/7NxXs3gETjlGkGIITAZSxHbdGVbiHYA7VTKn69OoYezlOxcgd2RTx+nLEv DkjguFkA6oacFVCOhRZGqblUMnxfDm5r7SG9nG1bHpt5XaUJ5354EIS2M1moca48 gRku2NfErtayNR0xh3ZnkkyzrSvNKVlA3f9SehpuXjwUK7YY0Rd0ynxBcIx/Ii5D rp2dhsT+uAH/9lRWVBzmUUqfOwfwpRxAQLhx50JcCap0fpRx6bLrakhMxhbf2XWv hJQfoMcI =k3Yq -----END PGP SIGNATURE-----</details>
Generalize/simplify VectorReader into SpanReader 2c35a93b3csipa force-pushed on Dec 2, 2021sipa commented at 7:48 PM on December 2, 2021: memberAddressed @MarcoFalke's comments.
DrahtBot commented at 4:01 AM on December 3, 2021: member<!--e57a25ab6845829454e8d69fc972939a-->
The following sections might be updated with supplementary metadata relevant to reviewers and maintainers.
<!--174a7506f384e20aa4161008e828411d-->
Conflicts
Reviewers, this pull request conflicts with the following ones:
- #23438 (refactor: Use spans of std::byte in serialize by MarcoFalke)
If you consider this pull request important, please also help to review the conflicting pull requests. Ideally, start with the one that should be merged first.
shaavan approvedshaavan commented at 8:33 AM on December 3, 2021: contributorACK 2c35a93b3cc19dc71d5664f9f61c24a04f419e35
MarcoFalke commented at 9:05 AM on December 3, 2021: memberre-ACK 2c35a93b3cc19dc71d5664f9f61c24a04f419e35 🖨
<details><summary>Show signature</summary>
Signature:
-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA512 re-ACK 2c35a93b3cc19dc71d5664f9f61c24a04f419e35 🖨 -----BEGIN PGP SIGNATURE----- iQGzBAEBCgAdFiEE+rVPoUahrI9sLGYTzit1aX5ppUgFAlwqrYAACgkQzit1aX5p pUgcPgv+KnKiX/J5RN0CHNr/DpP/v+1fhK27eioJvsEcH9DXAdY0Y/mntZ0mMOSZ rYAqSHTmDn9uFwwEu9QCffS5VRiyPdi3tb6X/v34uEiAQhOwVPA3o/b0D6fF3t17 AkEIM2uSX03yj1PSbpeeTkR8clP2B3Tc5SVcg+fCduDSeQCjAcBP94bIzqQBI18M 47GpVMBG6ZWLE3yvf/z0mdJq4/wmTRLUonpCQtHFHhtaTHm3FxxmsN7QOX9LwHEi oLMGM7qM/Ag09i+AC9mhuSBBi/tlyKGgtKNpmZITqZyT7Kc+bWodCcufbYhxOFl7 ylFE58QIyPpUbbLTxybu+2anvL/m9ABnXDxxqbiNG0DvqEhtSjZRzcq0nPsIYlMH 860ewOu0SU4XsMjMJzptEyfz/E5VQQbmIgGGMTg6iBezFuliYruQl09SsxcHJeFx eROywgR4zpvLtt0yONmyAU9tfq/2zbjlRJe7IeyMlXP8jOneqavZj7sa0zKJmk5c Tvx9RDcp =JgBF -----END PGP SIGNATURE-----</details>
MarcoFalke added the label Refactoring on Dec 3, 2021MarcoFalke merged this on Dec 3, 2021MarcoFalke closed this on Dec 3, 2021sidhujag referenced this in commit 25e1d70230 on Dec 3, 2021in src/streams.h:154 in 2c35a93b3c
153 | - if (m_pos > m_data.size()) { 154 | - throw std::ios_base::failure("VectorReader(...): end of data (m_pos > m_data.size())"); 155 | + if (pos > m_data.size()) { 156 | + throw std::ios_base::failure("SpanReader(...): end of data (pos > m_data.size())"); 157 | } 158 | + data = data.subspan(pos);
achow101 commented at 8:35 PM on December 6, 2021:Shouldn't this be
m_data = m_data.subspan(pos);
sipa commented at 8:37 PM on December 6, 2021:Ugh, yes! Will create a PR.
sipa commented at 8:38 PM on December 6, 2021:Actually, it looks like all call sites use
pos=0, which makes this harmless. With spans, having a separateposis also pointless as it can be easily done by the caller usingsubspan. I'm just going to drop it.
achow101 commented at 8:39 PM on December 6, 2021:I need it for PSBT things (which is how I found this bug). It would also be nice to have a test for other pos too.
sipa commented at 8:51 PM on December 6, 2021:MarcoFalke referenced this in commit b7e63306e8 on Dec 7, 2021sidhujag referenced this in commit 82cf06c9e2 on Dec 7, 2021jonatack commented at 5:46 PM on December 7, 2021: memberPost-merge ACK 2c35a93b3cc19dc71d5664f9f61c24a04f419e35
RandyMcMillan referenced this in commit 6c4c642027 on Dec 23, 2021RandyMcMillan referenced this in commit 3aa0c2ac7b on Dec 23, 2021DrahtBot locked this on Dec 7, 2022
This is a metadata mirror of the GitHub repository bitcoin/bitcoin. This site is not affiliated with GitHub. Content is generated from a GitHub metadata backup.
generated: 2026-05-02 12:14 UTC
More mirrored repositories can be found on mirror.b10c.me