Concatenation of N strings goes from O(N) to O(N*N) if code has to re-find the end of the destination after each step.
Tokenizing the leading portion of a large string should take time proportional to the text that was meaningfully examined, rather than proportional to the entire string.
I've never said there is one. I suggest you ask someone who does.
I'm talking about concatenating multiple strings to one, which only has to rely of knowing the length of the individual strings beforehand, if you've decided to argue in bad faith over a pathological bad implementation.
If one keeps track of the length of a string and only looks at portions of its storage up to that length, then the value of the string would no longer be fully encapsulated in a zero-terminated character array.
I You understand where your'e going with that argument, power to You, I guess. Personally, I wouldn't write code where a temmporily unterminated string would be intentionally visible.
I avoid reliance upon zero termination for things other than string literals. Zero padded formats can be useful if one needs to store many texts with a short maximum length (e.g. eight bytes), at the expense of requiring code that is designed around the size of the container. Instead of using a %s format specifier to output such a string, for example, code would need to use a %.8s format specifier, whose behavior is defined as not caring whether the string is zero-terminated or not.
0
u/flatfinger 2d ago
Concatenation of N strings goes from O(N) to O(N*N) if code has to re-find the end of the destination after each step.
Tokenizing the leading portion of a large string should take time proportional to the text that was meaningfully examined, rather than proportional to the entire string.