3 ms·
> I had to work with fixed-size ASCII strings that are not NUL-terminated and are, instead, padded with spaces at the end. When I have strings on performance-c
by Const-me 5y ago
> I had to work with fixed-size ASCII strings that are not NUL-terminated and are, instead, padded with spaces at the end.
When I have strings on performance-critical paths, unless they’re too long for a good reason, I sometimes pad them with \0 and limiting them to 16- or 32-bytes length. This way I can pass strings in a vector register by value (i.e. __m128i or __m256i data type in C++), and they’re very efficient to deal with. For instance, comparing them for equality only takes two instructions, vpxor and vptest (_mm_xor_si128 and _mm_testz_si128 intrinsics for 16-byte vectors), that’s 3-4 cycles of latency, an order of magnitude better than comparing traditional C or C++ strings.
I don’t have any experience with dlang though, not sure how easy or hard to implement that in D.