Some cases were treated independently while retaining mostly the same
code.
This commit tries to unite such cases into a single branch.
Doing so helps readability, reduces code duplication and should
hopefully improve performance as the number of tests to be performed is
lower.
Signed-off-by: Lucas Bajolet <lucas.bajolet@gmail.com>
Pull-Request: #2640
Reviewed-by: Alexis Laferrière <alexis.laf@xymus.net>