code optimization in HistoryDlg::displayResult

Moving the part of the code out of the loop.