Dave Cheney <
da...@cheney.net> writes:
> You make a good point. I was originally going to say you were sweating
> over one additional line, but the argument for the overhead of two
> hash lookups is valid, but probably quite small compared the network
> time of sending the 'deleted, but wasn't there in the first place'
> message.
Probably true, but the most common case is deleting things that were
there. So in the common path, I have to make two passes. Only in the
uncommon paths do I get to short-circuit it. So it's faster when it's
less likely. :)
You could imagine a similar thing being used as an assertion. If my
program is correct, I will only delete things that I have actually
added. So I can write delete like the following with no measurable
performance impact:
if !delete(m, key) {
panic(fmt.Errorf("Deletion of missing key %v", key))
}
--
dustin