[base] Fix use of bsearch

pull/1878/head
Ebrahim Byagowi 5 years ago committed by GitHub
parent eddd456532
commit a157342fce
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 92
      src/hb-ot-layout-base-table.hh

@ -1,7 +1,7 @@
/*
* Copyright © 2016 Elie Roux <elie.roux@telecom-bretagne.eu>
* Copyright © 2018 Google, Inc.
* Copyright © 2018 Ebrahim Byagowi
* Copyright © 2018-2019 Ebrahim Byagowi
*
* This is part of HarfBuzz, a text shaping library.
*
@ -32,9 +32,6 @@
#include "hb-open-type.hh"
#include "hb-ot-layout-common.hh"
/* To be removed */
typedef hb_tag_t hb_ot_layout_baseline_t;
namespace OT {
/*
@ -153,14 +150,9 @@ struct BaseCoord
struct FeatMinMaxRecord
{
HB_INTERNAL static int cmp (const void *key_, const void *entry_)
{
hb_tag_t key = * (hb_tag_t *) key_;
const FeatMinMaxRecord &entry = * (const FeatMinMaxRecord *) entry_;
return key < (unsigned int) entry.tag ? -1 :
key > (unsigned int) entry.tag ? 1 :
0;
}
int cmp (hb_tag_t key) const { return tag.cmp (key); }
bool has_data () const { return tag; }
void get_min_max (const BaseCoord **min, const BaseCoord **max) const
{
@ -198,14 +190,9 @@ struct MinMax
const BaseCoord **min,
const BaseCoord **max) const
{
/* TODO Replace hb_bsearch() with .bsearch(). */
const FeatMinMaxRecord *minMaxCoord = (const FeatMinMaxRecord *)
hb_bsearch (&feature_tag, featMinMaxRecords.arrayZ,
featMinMaxRecords.len,
FeatMinMaxRecord::static_size,
FeatMinMaxRecord::cmp);
if (minMaxCoord)
minMaxCoord->get_min_max (min, max);
const FeatMinMaxRecord &minMaxCoord = featMinMaxRecords.bsearch (feature_tag);
if (minMaxCoord.has_data ())
minMaxCoord.get_min_max (min, max);
else
{
if (likely (min)) *min = &(this+minCoord);
@ -271,14 +258,9 @@ struct BaseValues
struct BaseLangSysRecord
{
HB_INTERNAL static int cmp (const void *key_, const void *entry_)
{
hb_tag_t key = * (hb_tag_t *) key_;
const BaseLangSysRecord &entry = * (const BaseLangSysRecord *) entry_;
return key < (unsigned int) entry.baseLangSysTag ? -1 :
key > (unsigned int) entry.baseLangSysTag ? 1 :
0;
}
int cmp (hb_tag_t key) const { return baseLangSysTag.cmp (key); }
bool has_data () const { return baseLangSysTag; }
const MinMax &get_min_max () const
{ return this+minMax; }
@ -303,19 +285,14 @@ struct BaseScript
{
const MinMax &get_min_max (hb_tag_t language_tag) const
{
/* TODO Replace hb_bsearch() with .bsearch(). */
const BaseLangSysRecord* record = (const BaseLangSysRecord *)
hb_bsearch (&language_tag, baseLangSysRecords.arrayZ,
baseLangSysRecords.len,
BaseLangSysRecord::static_size,
BaseLangSysRecord::cmp);
return record ? record->get_min_max () : this+defaultMinMax;
const BaseLangSysRecord& record = baseLangSysRecords.bsearch (language_tag);
return record.has_data () ? record.get_min_max () : this+defaultMinMax;
}
const BaseCoord &get_base_coord (int baseline_tag_index) const
{ return (this+baseValues).get_base_coord (baseline_tag_index); }
bool is_empty () const { return !baseValues; }
bool has_data () const { return baseValues; }
bool sanitize (hb_sanitize_context_t *c) const
{
@ -345,14 +322,9 @@ struct BaseScript
struct BaseScriptList;
struct BaseScriptRecord
{
HB_INTERNAL static int cmp (const void *key_, const void *entry_)
{
hb_tag_t key = * (hb_tag_t *) key_;
const BaseScriptRecord &entry = * (const BaseScriptRecord *) entry_;
return key < (unsigned int) entry.baseScriptTag ? -1 :
key > (unsigned int) entry.baseScriptTag ? 1 :
0;
}
int cmp (hb_tag_t key) const { return baseScriptTag.cmp (key); }
bool has_data () const { return baseScriptTag; }
const BaseScript &get_base_script (const BaseScriptList *list) const
{ return list+baseScript; }
@ -376,20 +348,11 @@ struct BaseScriptRecord
struct BaseScriptList
{
const BaseScriptRecord *find_record (hb_tag_t script) const
{
/* TODO Replace hb_bsearch() with .bsearch(). */
return (const BaseScriptRecord *) hb_bsearch (&script, baseScriptRecords.arrayZ,
baseScriptRecords.len,
BaseScriptRecord::static_size,
BaseScriptRecord::cmp);
}
/* TODO: Or client should handle fallback? */
const BaseScript &get_base_script (hb_tag_t script) const
{
const BaseScriptRecord *record = find_record (script);
if (!record) record = find_record ((hb_script_t) HB_TAG ('D','F','L','T'));
const BaseScriptRecord *record = &baseScriptRecords.bsearch (script);
/* TODO: Or client should handle fallback? */
if (!record->has_data ()) record = &baseScriptRecords.bsearch (HB_TAG ('D','F','L','T'));
return record ? record->get_base_script (this) : Null (BaseScript);
}
@ -417,9 +380,14 @@ struct Axis
const BaseCoord **coord) const
{
const BaseScript &base_script = (this+baseScriptList).get_base_script (script_tag);
if (base_script.is_empty ()) return false;
if (!base_script.has_data ()) return false;
if (likely (coord)) *coord = &base_script.get_base_coord ((this+baseTagList).bsearch (baseline));
if (likely (coord))
{
unsigned int tag_index = 0;
(this+baseTagList).bfind (baseline, &tag_index);
*coord = &base_script.get_base_coord (tag_index);
}
return true;
}
@ -431,7 +399,7 @@ struct Axis
const BaseCoord **max_coord) const
{
const BaseScript &base_script = (this+baseScriptList).get_base_script (script_tag);
if (base_script.is_empty ()) return false;
if (!base_script.has_data ()) return false;
base_script.get_min_max (language_tag).get_min_max (feature_tag, min_coord, max_coord);
@ -483,9 +451,9 @@ struct BASE
if (!get_axis (direction).get_baseline (baseline, script_tag, language_tag, &base_coord))
return false;
if (likely (base && base_coord)) *base = base_coord->get_coord (font,
get_var_store (),
direction);
if (likely (base && base_coord))
*base = base_coord->get_coord (font, get_var_store (), direction);
return true;
}

Loading…
Cancel
Save