3 ms·
Who cares if it's O(1) if it causes a panic? What good is high performance if it doesn't complete or isn't safe? At the very least, shouldn't there be an O(n)
by da_chicken 8y ago
Who cares if it's O(1) if it causes a panic? What good is high performance if it doesn't complete or isn't safe?
At the very least, shouldn't there be an O(n) method to do character-wise slicing?
- steveklabnik 8y agopanics are safe. You expect the “I don’t have a bug” case to be fast. You can, but it depends on what you mean by “character”, as that’s not a concept in Unicode. Every kind of thing you could mean has a method, specific to it, since they’re different things. (char in Rust is a Unicode scalar value, and you can collect into a Vec<char> and then slice it, as an example of one of those things. And that’s still O(1) at the cost of using up to four times the memory.)