Here's a speed-up I did a while ago.
Created attachment 16735 [details] patch
Created attachment 16736 [details] patch
Comment on attachment 16736 [details] patch r=me
Committed revision 26827.