This code could use a full rewrite but there are also some simple optimizations that can be done.
Created attachment 456687 [details] Patch
Committed r292418 (249281@main): <https://commits.webkit.org/249281@main> All reviewed patches have been landed. Closing bug and clearing flags on attachment 456687 [details].
<rdar://problem/91312118>