std::string_view is much more efficient when it comes to string handling and should be used in place of std::string wherever possible to prevent heavy copying. Caching WrapText calls to reduce the overhead on text parsing when it comes to displaying text by having a wrapped version of each label stored in memory and utilizing that instead of calculating and manipulating the string every frame on-the-fly.
`std::string_view` is much more efficient when it comes to string handling and should be used in place of `std::string` wherever possible to prevent heavy copying. Caching `WrapText` calls to reduce the overhead on text parsing when it comes to displaying text by having a wrapped version of each label stored in memory and utilizing that instead of calculating and manipulating the string every frame on-the-fly.
The current WrapText implementation assumes we want to modify the string. But thinking about what wrapping text does internally, we update a position marker and when we reach a point beyond the desired width, we move the position marker down and back over. This can all be accomplished with a string view and doesn't actually need a string copy operation, or multiple for that matter, which are very very expensive.
Do this inside the current draw text functions with a wrap text flag and we get wrapping text almost for free.
The current `WrapText` implementation assumes we want to modify the string. But thinking about what wrapping text does internally, we update a position marker and when we reach a point beyond the desired width, we move the position marker down and back over. This can all be accomplished with a string view and doesn't actually need a string copy operation, or multiple for that matter, which are very very expensive.
Do this inside the current draw text functions with a wrap text flag and we get wrapping text almost for free.
Commit d29f7d47bd addresses the WrapText implementation and has incorporated the wrapping completely within the DrawString and GetTextSize functions.
As those are our only use cases for text wrapping, this is ideal.
Commit http://sig.projectdivar.com/sigonasr2/Crawler/commit/d29f7d47bd614b0701cbb63d020b59de04c25d9e addresses the WrapText implementation and has incorporated the wrapping completely within the `DrawString` and `GetTextSize` functions.
As those are our only use cases for text wrapping, this is ideal.
std::string_view
is much more efficient when it comes to string handling and should be used in place ofstd::string
wherever possible to prevent heavy copying. CachingWrapText
calls to reduce the overhead on text parsing when it comes to displaying text by having a wrapped version of each label stored in memory and utilizing that instead of calculating and manipulating the string every frame on-the-fly.The current
WrapText
implementation assumes we want to modify the string. But thinking about what wrapping text does internally, we update a position marker and when we reach a point beyond the desired width, we move the position marker down and back over. This can all be accomplished with a string view and doesn't actually need a string copy operation, or multiple for that matter, which are very very expensive.Do this inside the current draw text functions with a wrap text flag and we get wrapping text almost for free.
Commit
d29f7d47bd
addresses the WrapText implementation and has incorporated the wrapping completely within theDrawString
andGetTextSize
functions.As those are our only use cases for text wrapping, this is ideal.
Completed in commit
5d1e0b5a7a