LibertyOS-Development / kernel

The kernel for LibertyOS.
Apache License 2.0
277 stars 12 forks source link

Improve performance of creating and filling a vector in line 56 of src/main.rs #11

Closed mycielski closed 2 years ago

mycielski commented 2 years ago

In line 56 of src/main.rs there is an inefficient creation and population of a vector. This pull request improves this by creating and populating the vector with iterator collect instead of a for loop which pushes a number onto vector with each iteration. This optimization was originally noticed by reddit user NateReinarWoodwind.

danielteberian commented 2 years ago

Hey, man! I appreciate the PR, but I have a question for you. When compiling the kernel, after merging your changes, I get a warning about a variable that is made mutable, despite (according to the compiler) having no reason to be mutable. Do you know why this variable is mutable, and if it needs to be mutable?

mycielski commented 2 years ago

That's strange. As you can see my commit only changed the way the vector is populated, not its mutability or its usage. Also, I could not replicate the warning. I have tried cargo checking and compiler returned no warnings (it does however return warnings and errors on cargo test, but that's unrelated). I am on nightly-x86_64-pc-windows-msvc toolchain