Small optimization in "samewith"