42 ms·
But you could just as easily set aside the first 4 bytes of a string to be the length and then it would be O(1). But does that really matter when you're doing
by daemin 15y ago
But you could just as easily set aside the first 4 bytes of a string to be the length and then it would be O(1).
But does that really matter when you're doing operations on the string that iterate over the whole string anyway? Since iterating the whole string is O(n) anyway, you're not really gaining anything.
- fuzzix 15y agoOperations to return string length or return characters from the end of the string become far less expensive. You also have a fair idea of a reasonable sized buffer to move in duplication operations, avoiding single character move loops.