Yes, that is how it works at the moment, which obviously isn't good on showflat. It will be more as well as each post which has UBBCode turned on will also call the do_markup once each.
I have been trying to think of a way to only do the query once but haven't decided on anything yet so any input would be welcome.
One way could be to put the array as a global variable in the html class and only read from the db if the array is empty. Would that be sufficient?