Optimize getPartitions()