keepass-diff icon indicating copy to clipboard operation
keepass-diff copied to clipboard

refactor code

Open LorenzSchueler opened this issue 1 year ago • 2 comments

While debugging a problem (which turns out to be caused by my password manager) I just started to refactor the code to make it easier to read and understand. The main changes are:

  • replace custom Stack by std::vec::Vec
  • make fields private and use constructors for costruction of types
  • make more use of iterator adapters
  • apply lints

Not sure if you want any of those changes. In case you only want some of them I can also revert the others.

LorenzSchueler avatar Nov 26 '23 13:11 LorenzSchueler

Sorry for not getting back to this. I've only had time to skim over the changes as there was lots of private and work related stuff going on. There are lots of nice improvements regarding the code and where I obviously didn't know about some functions or how to do it properly with Rust. I definitely want to understand what has been changed and incorporate things like this into the code. It's a bit much for one PR, so I have postponed properly checking it for forever. I hope in a few weeks from now I have more time for this project here again and will be able to get this code base and everything around it more polished into something that can be downloaded and used.

Narigo avatar Jan 30 '24 01:01 Narigo

I am also working on similar changes using cargo clippy but I for now am trying not to touch main.rs as I believe there should be a bigger refactor on execution flow and maybe replace some variable declarations. Good examples would be:

  • Replace String in favor of Box<str> as the former is a struct that is approximately usize * 3 (pointer + current length + capacity) and the latter is just a fat pointer (pointer + len). Also after initial command line read, the variables are no longer mutated so we don't methods for extending the allocation.
  • Find a way to less data cloning and use more referencing as each clone op is O(n) where n is equal to password length.

mrghosti3 avatar Jan 31 '24 20:01 mrghosti3