Further optimize getPartitions()