Skip to content

Conversation

@theStack
Copy link
Contributor

@theStack theStack commented Mar 28, 2021

This refactoring PR deduplicates repeated SQLite statement preparation calls (sqlite3_prepare_v2(...)) / deletions (sqlite3_finalize(...)) and its surrounding logic by putting each prepared statement and its corresponding text representation into a std::map std::array std::vector. This should be more readable and less error-prone, e.g. in case an additional statement needs to be added in the future or the error handling has to be adapted.

@S3RK
Copy link
Contributor

S3RK commented Mar 29, 2021

Code review ACK 966089a

@Empact
Copy link
Contributor

Empact commented Mar 30, 2021

Concept ACK - the resulting code is significantly more readable IMO and this makes the consistent treatment obvious and enforced.

Logically, the underlying values in statements are not associated as in a map (i.e. the indexing linking the values is not relevant - one is not logically a key and the other a value). A std::array<std::tuple> would seem to be more logically consistent.

@theStack theStack force-pushed the 2021-wallet-dedup_setupsqlstatements branch from 966089a to 0df8012 Compare March 30, 2021 11:45
@theStack
Copy link
Contributor Author

Thanks for reviewing!

Logically, the underlying values in statements are not associated as in a map (i.e. the indexing linking the values is not relevant - one is not logically a key and the other a value). A std::array<std::tuple> would seem to be more logically consistent.

Agreed, using std::map here is like using a sledgehammer to crack a nut 😄 I changed the code to use std::array<std::pair<...,...>, N> now -- fortunately the loop code doesn't need to be changed at all. The only drawback is that we need to specify the size N of the array as second template parameter (std::make_array would help here, but that is not in the standard yet as far as I know), but I think we can live with that.

@S3RK
Copy link
Contributor

S3RK commented Mar 31, 2021

reACK 0df8012. The only change is replacing map with array

Copy link
Member

@maflcko maflcko left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Any reason to change this method, but not the Close method?

@theStack theStack force-pushed the 2021-wallet-dedup_setupsqlstatements branch from 0df8012 to ea19cc8 Compare April 2, 2021 13:57
@theStack theStack changed the title wallet: refactor: dedup sqlite statement preparations wallet: refactor: dedup sqlite statement preparations/deletions Apr 2, 2021
@theStack
Copy link
Contributor Author

theStack commented Apr 2, 2021

Took in the suggestions by MarcoFalke (#21540 (review)): applied clang-format, changed table type from std::array to std::vector to avoid typing the size and add another commit to also deduplicate the deletion of statements (sqlite3_finalize(...)). Thanks for reviewing!

@achow101
Copy link
Member

achow101 commented Apr 2, 2021

ACK ea19cc8

Copy link
Contributor

@meshcollider meshcollider left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

utACK ea19cc8

@fanquake
Copy link
Member

fanquake commented Apr 7, 2021

It was while testing this I noticed #21628. However the issue is also present in master.

@fanquake fanquake merged commit c0160ea into bitcoin:master Apr 7, 2021
sidhujag pushed a commit to syscoin/syscoin that referenced this pull request Apr 7, 2021
…tions/deletions

ea19cc8 wallet: refactor: dedup sqlite statement deletions (Sebastian Falbesoner)
9a36709 wallet: refactor: dedup sqlite statement preparations (Sebastian Falbesoner)

Pull request description:

  This refactoring PR deduplicates repeated SQLite statement preparation calls (`sqlite3_prepare_v2(...)`) / deletions (`sqlite3_finalize(...)`) and its surrounding logic by putting each prepared statement and its corresponding text representation into a ~std::map~ ~`std::array`~ `std::vector`. This should be more readable and less error-prone, e.g. in case an additional statement needs to be added in the  future or the error handling has to be adapted.

ACKs for top commit:
  achow101:
    ACK ea19cc8
  meshcollider:
    utACK ea19cc8

Tree-SHA512: ced89869b2147e088e7a4cda2acbbdd4a806f66dbc2d6999953d0d702c0655aa53c0eb699cc7e5e3732f2d24206d577a9d9e1b5de7f439100dead2696ade1092
@theStack theStack deleted the 2021-wallet-dedup_setupsqlstatements branch July 31, 2021 20:08
@bitcoin bitcoin locked as resolved and limited conversation to collaborators Aug 18, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants