Skip to content

implement minor improvements in existing code#91

Open
mick-lue wants to merge 2 commits intoModOrganizer2:masterfrom
mick-lue:minor_improvements
Open

implement minor improvements in existing code#91
mick-lue wants to merge 2 commits intoModOrganizer2:masterfrom
mick-lue:minor_improvements

Conversation

@mick-lue
Copy link
Copy Markdown

Going through the code, I encountered a few instances where minor improvements can be made.

tree_container.h

  • std::format avoids creating temporary strings that then get concatenated, allowing the compiler to do in-place string construction.

winapi

  • we can pass the path object as a const reference to avoid copying it for the (recursive) function call createPath.

ttrampolinepool.cpp

  • using try_emplace instead of insert allows creating the pair in-place without instantiating a local object first. It will also instantiate a default BufferList() as before, but I added a comment to make it clear
  • using buffers.empty() can be more efficient than comparing to buffers.size() depending on the implementation of size() and makes the code easier to understand
  • using !m_ThreadGuards->contains(func) makes the code easier to understand

hookmanager.cpp

  • try_emplace allows in-place construction

maptracker.h

  • see winapi, same code for createFakePath as createPath
  • the explicit call to std::move when returning a local variable prevents the compiler from doing copy elision optimizations here. Without it, the compiler can potentially further optimize the function.

usvfs.cpp

  • using constant references to the library strings prevents temporary copies of those strings
  • as RedirectionTree::exists accepts a string_view there is no need to transform the iterator string to a c_str.

Tests

All tests still pass and I've had no issues using MO2, starting programs or games through MO2 and playing heavily-modded skyrirm for example.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant