I would, at some point, love to see this function profiled. I suspect there are some low-hanging optimization fruit, but I couldn't guess where.