[svg] Use SortedArrayOf.bsearch

This commit is contained in:
Behdad Esfahbod 2018-10-28 18:29:14 -07:00
parent 18dd6363a5
commit 9c1460e568
1 changed files with 3 additions and 15 deletions

View File

@ -43,13 +43,6 @@ struct SVGDocumentIndexEntry
inline int cmp (hb_codepoint_t g) const inline int cmp (hb_codepoint_t g) const
{ return g < startGlyphID ? -1 : g > endGlyphID ? 1 : 0; } { return g < startGlyphID ? -1 : g > endGlyphID ? 1 : 0; }
static int cmp (const void *pa, const void *pb)
{
const hb_codepoint_t *a = (const hb_codepoint_t *) pa;
const SVGDocumentIndexEntry *b = (const SVGDocumentIndexEntry *) pb;
return b->cmp (*a);
}
inline hb_blob_t *reference_blob (hb_blob_t *svg_blob, unsigned int index_offset) const inline hb_blob_t *reference_blob (hb_blob_t *svg_blob, unsigned int index_offset) const
{ {
if (svgDocLength == 0) return hb_blob_get_empty (); if (svgDocLength == 0) return hb_blob_get_empty ();
@ -113,13 +106,8 @@ struct SVG
inline const SVGDocumentIndexEntry &get_glyph_entry (hb_codepoint_t glyph_id) const inline const SVGDocumentIndexEntry &get_glyph_entry (hb_codepoint_t glyph_id) const
{ {
const SVGDocumentIndexEntry *rec = (SVGDocumentIndexEntry *) const SortedArrayOf<SVGDocumentIndexEntry> docs = this+svgDocEntries;
bsearch (&glyph_id, return docs[docs.bsearch (glyph_id)];
&(this+svgDocEntries).arrayZ,
(this+svgDocEntries).len,
sizeof (SVGDocumentIndexEntry),
SVGDocumentIndexEntry::cmp);
return likely (rec) ? *rec : Null(SVGDocumentIndexEntry);
} }
inline bool sanitize (hb_sanitize_context_t *c) const inline bool sanitize (hb_sanitize_context_t *c) const
@ -131,7 +119,7 @@ struct SVG
protected: protected:
HBUINT16 version; /* Table version (starting at 0). */ HBUINT16 version; /* Table version (starting at 0). */
LOffsetTo<ArrayOf<SVGDocumentIndexEntry> > LOffsetTo<SortedArrayOf<SVGDocumentIndexEntry> >
svgDocEntries; /* Offset (relative to the start of the SVG table) to the svgDocEntries; /* Offset (relative to the start of the SVG table) to the
* SVG Documents Index. Must be non-zero. */ * SVG Documents Index. Must be non-zero. */
/* Array of SVG Document Index Entries. */ /* Array of SVG Document Index Entries. */