iolivia / rust-sokoban

Rust Sokoban book and code samples
https://sokoban.iolivia.me
MIT License
155 stars 29 forks source link

Remove unnecessary allocation of a Vec #65

Closed pwoolcoc closed 4 years ago

pwoolcoc commented 4 years ago

In input_system.rs, we are collecting into a Vec, converting it into an iterator, and collecting again into a Hashmap. The initial collection into the Vec is unnecessary and we can just collect directly into the HashMap

iolivia commented 4 years ago

this is awesome, thanks @pwoolcoc! I think this code is also present in 2.3, do you want to remove it from there as well? might need to fix a couple of line numbers in the md file for that section but should not be too bad.

pwoolcoc commented 4 years ago

@iolivia thanks! I found a few more instances of this pattern so I fixed those as well. I adjusted the line numbers in Ch2-03, as well as scanned through the rest of the book to see if any obvious issues jumped out at me. I didn't find any more code samples that looked off but I'm happy to fix any I may have missed.

iolivia commented 4 years ago

thanks @pwoolcoc, this is a great fix! I had a look at the netlify preview as well and couldn't see any broken code samples, so we should be good to go.