> That function however is used in 4 other places in the same file, changing to a while loop will not only make the function slower but will also break other code.

Neither of these two claims are true. All fetchrowset does is loop over all rows, see https://github.com/phpbb/phpbb/blob/develop/phpBB/phpbb/db/driver/driver.php#L179. You can just replace fetchrowset with a while loop constructing an array that has the same values and uses the style ids as array keys.