fdo#73147 improve function code for speed

Change-Id: I8862c1aaf245796a475ce52bec6c8e9a32862bbd
Reviewed-on: https://gerrit.libreoffice.org/8841
Reviewed-by: Eike Rathke <erack@redhat.com>
Tested-by: Eike Rathke <erack@redhat.com>