How would you optimize a function that is currently a performance bottleneck?
For this task, the bottleneck counts every pair of equal values in an integer array. Implement an optimized replacement that returns the number of index pairs (i, j) where i < j and values[i] == values[j].
Input/output contract: values is a list of integers; return an integer count. The result must be correct for duplicate values, negative values, and an empty list.
def count_duplicate_pairs(values):