Implemented some optimizations for set union/intersection/difference which check for reference equality or empty inputs to avoid unnecessary computation.