Change ShapeResult::LimitNumGlyphs to use binary-search

CL:1370147 discusses the possibility of the pre-shape limit.
Pre-shape limit is faster because it has character array and
that the limit is index-based operations.

Dominik pointed out that the post-shape limit is still needed
even if we have the pre-shape limit because HarfBuzz cluster
is different from the Unicode grapheme cluster, and also the
pre-shape limit may be incorrect for the same reason.

This patch changes ShapeResult::LimitNumGlyphs to use binary
search algorithm to speed it up when the pre-shape limit was
different from HarfBuzz cluster, or when we may not have the
pre-shape limit.

This change improves long-line-nowrap by 17%.
https://pinpoint-dot-chromeperf.appspot.com/job/1492a623140000

This patch has no behavior changes. Tests for this change is
covered by:
  HarfBuzzShaperTest/ShapeParameterTest.MaxGlyphs
      {Simple,ClusterLatin,ClusterLatin2,ClusterDevanagari}
      /{0,1} (0 and 1 are for LTR and RTL)

Bug: 636993, 893967
Change-Id: Ifdf2d094e72cdfc6259d72d4e27511679b095ab2
Reviewed-on: https://chromium-review.googlesource.com/c/1388356
Reviewed-by: Dominik Röttsches <drott@chromium.org>
Commit-Queue: Koji Ishii <kojii@chromium.org>
Cr-Commit-Position: refs/heads/master@{#620620}
1 file changed