improve array intersect/union. fixes #4725