3 ms·
There is an explanation in the article - basically, this is done for performance reasons. Especially for large types (e.g. collections) in-equality can short-c
by tsimionescu 7y ago
There is an explanation in the article - basically, this is done for performance reasons.
Especially for large types (e.g. collections) in-equality can short-circuit very quickly, whereas comparison may need to see a large part of the collection before being able to return.
The most pathological example is two large arrays of different size, that are element-by-element equal for the first million elements. Equality can return false after seeing the size difference, but <=> needs to reach the millionth-and-1 element before being bale to return a value.
The commission was especially concerned because the two operators would be functionally equivalent - so, it would be difficult to rely on testing to make sure the equality operator is also implemented.