Widget: Improve performance of cleanData method

Fixes #9546
Closes gh-1291