Home » Community » U++ community news and announcements » String::Make - new way how to create a small string fast
String::Make - new way how to create a small string fast [message #57545] |
Sat, 18 September 2021 17:31  |
 |
mirek
Messages: 14255 Registered: November 2005
|
Ultimate Member |
|
|
While optimizing conversion routines, I have found a relative bottleneck when converting small char buffers to String. To solve that, there is now a new static method
template <class Maker> static String Make(int alloc, Maker m)
Optimized static method for creating Strings. This method creates internal buffer of at least alloc and then invokes lambda m passing the char * pointer to the internal buffer as lambda parameter. Lambda is then supposed to fill the characters to this buffer and return the length of string (which must be <= alloc). For the best performance, alloc should be constant.
Example:
String x = String::Make(12, [](char *t) { *t++ = 'X'; return 1; });
[Updated on: Sat, 26 February 2022 18:51] Report message to a moderator
|
|
|
|
|
|
Goto Forum:
Current Time: Tue Apr 29 16:06:02 CEST 2025
Total time taken to generate the page: 0.00902 seconds
|