Use function outside of loop

Otherwise the function is executed n times which is a lot of overhead
Merge pull request #11752 from owncloud/use-function-outside-of-loop

Use function outside of loop