inlined overlap check for better performance