cmList: Fix performance regression in append/prepend

Fixes: #25147
3 files changed