C++ quick matrix calculation of XDX^T for X fixed, D diagonal and changing

Take a fixed n by m matrix X. I am interested in creating a function which takes in an m dimensional vector v, and outputs XDX^T where D is a diagonal matrix with entries of v along its diagonals. For fast calculation (here n is around 2000, m can be from 10000 to 100000), my idea is based on one observation.

Note that XDX^T = sum_{i=1,...,m} (Y_i Y_i^T)*v_i where Y_i are the columns of X (so X = [Y_1 Y_2 .... Y_m].

So initially we pre-caculate and save the n by n matrices (Y_i Y_i^T) for i=1,...,m. This will be saved as an array of m matrices. Then we create a function which takes this array of matrices and v as input, applies element wise multiplication behind v and the array, then returns the sum of the m matrices.

However, I am very new to C++, and efficiently writing this program is difficult. Any help on doing this quickly, and whether this is a good idea? At the moment I am calculate XDX^T using crossproduct function in the Eigen library. My intuition is the above method should be much faster (we are trading off memory for speed). Thanks.