Optimize SVGTextQuery's character offset ligature adjustment query

For queries that take a code unit to compute some property for (basically
all *OfChar calls), the <start, end> range is mapped to the closest
glyph-boundary to allow queries within ligatures.
This adjustment step is O(N), N=number of glyphs within a text node, and
is performed for each fragment within a text box.
This means that for text boxes with a large number of fragments - and,
consequently, a large number of glyphs - there'll be O(N^2) behavior.
Since the <start, end> range is invariant for most queries, it should
suffice to compute the adjusted range once per text node [1].
The easiest way to achieve this is by adding a simple cache and reuse the
result of an adjustment query (for every fragment in a text box.)

This improves the runtime of the test in the bug from ~13s to ~120ms (or
approximately a factor 100) locally.

[1] This CL however only perform caching per text box in order to minimize
modifications to the actual adjustment code.

BUG=267504

Review URL: https://codereview.chromium.org/349223003

git-svn-id: svn://svn.chromium.org/blink/trunk@176937 bbb929c8-8fbe-4397-9dbb-9b2b20218538
1 file changed
tree: 1fa33348d73ad0accdbb6ba3e7a07f6cdb331bbb
  1. third_party/