From 19a2b2e417fe80e83e2d2964db70451835abb4d4 Mon Sep 17 00:00:00 2001 From: Kristoffer Carlsson Date: Sat, 17 Aug 2019 13:13:47 +0200 Subject: [PATCH] add a note on checking for equality with singletons (#28700) * add a note on checking for equality with singletons --- doc/src/manual/performance-tips.md | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/doc/src/manual/performance-tips.md b/doc/src/manual/performance-tips.md index e04305526c54d..c44a0fe007c4d 100644 --- a/doc/src/manual/performance-tips.md +++ b/doc/src/manual/performance-tips.md @@ -1513,3 +1513,11 @@ will not require this degree of programmer annotation to attain performance. In the mean time, some user-contributed packages like [FastClosures](https://github.com/c42f/FastClosures.jl) automate the insertion of `let` statements as in `abmult3`. + +# Checking for equality with a singleton + +When checking if a value is equal to some singleton it can be +better for performance to check for identicality (`===`) instead of +equality (`==`). The same advice applies to using `!==` over `!=`. +These type of checks frequently occur e.g. when implementing the iteration +protocol and checking if `nothing` is returned from [`iterate`](@ref).