Optimization to building DIIS matrix