aafulei / color-console

A lightweight header-only C++ library to bring colors to your Windows console with a very-easy-to-use API.
MIT License
258 stars 47 forks source link

Avoid unnecessary Allocations and Copys #4

Open TobiasWallner opened 3 years ago

TobiasWallner commented 3 years ago

You are using a lot of std::string types and always copy them. Consider using const char* pointer since you are only using raw literal strings. This will avoid unnecessary copys and allocations (this of course depends on the implementation of std::string and if its using short string optimisation)

And I took a deeper look at your code. Why are you not just using an enum value that already has the value needed for the win32 api? Something like

enum class hue {black = 0, .... }

Then you would just need to overload the stream operator for the enum.

Patrix9999 commented 8 months ago

Hi, i know that many years have past since this issue has been opened, but i've decided recently to make my own version of this library using your suggestions: https://github.com/Patrix9999/console-color

Maybe this will help someone.