[feat] Use bsearch

This commit is contained in:
Ebrahim Byagowi 2018-11-17 14:23:11 +03:30 committed by Behdad Esfahbod
parent 4009a05ca7
commit a8726cb483
3 changed files with 25 additions and 15 deletions

View File

@ -39,17 +39,25 @@ namespace AAT {
struct SettingName struct SettingName
{ {
inline bool sanitize (hb_sanitize_context_t *c) const static int cmp (const void *key_, const void *entry_)
{ {
TRACE_SANITIZE (this); hb_aat_layout_feature_setting_t key = * (hb_aat_layout_feature_setting_t *) key_;
return_trace (likely (c->check_struct (this))); const SettingName * entry = (const SettingName *) entry_;
return key < entry->setting ? -1 :
key > entry->setting ? +1 :
0;
} }
inline hb_aat_layout_feature_setting_t get_setting () const inline hb_aat_layout_feature_setting_t get_setting () const
{ return (hb_aat_layout_feature_setting_t) (unsigned int) setting; } { return (hb_aat_layout_feature_setting_t) (unsigned int) setting; }
inline hb_ot_name_id_t get_name_id () const inline hb_ot_name_id_t get_name_id () const { return nameIndex; }
{ return (hb_ot_name_id_t) nameIndex; }
inline bool sanitize (hb_sanitize_context_t *c) const
{
TRACE_SANITIZE (this);
return_trace (likely (c->check_struct (this)));
}
protected: protected:
HBUINT16 setting; /* The setting. */ HBUINT16 setting; /* The setting. */
@ -113,17 +121,17 @@ struct FeatureName
inline hb_aat_layout_feature_type_t get_feature_type () const inline hb_aat_layout_feature_type_t get_feature_type () const
{ return (hb_aat_layout_feature_type_t) (unsigned int) feature; } { return (hb_aat_layout_feature_type_t) (unsigned int) feature; }
inline hb_ot_name_id_t get_feature_name_id () const inline hb_ot_name_id_t get_feature_name_id () const { return nameIndex; }
{ return (hb_ot_name_id_t) nameIndex; }
inline hb_ot_name_id_t get_feature_setting_name_id (const feat *feat, inline hb_ot_name_id_t get_feature_setting_name_id (const feat *feat,
hb_aat_layout_feature_setting_t setting) const hb_aat_layout_feature_setting_t key) const
{ {
const UnsizedArrayOf<SettingName>& settings_table = feat+settingTableZ; const SettingName* setting = (SettingName*) hb_bsearch (&key, feat+settingTableZ,
for (unsigned int i = 0; i < nSettings; i++) nSettings,
if (settings_table[i].get_setting () == setting) SettingName::static_size,
return settings_table[i].get_name_id (); SettingName::cmp);
return HB_OT_NAME_ID_INVALID;
return setting ? setting->get_name_id () : HB_OT_NAME_ID_INVALID;
} }
inline bool sanitize (hb_sanitize_context_t *c, const void *base) const inline bool sanitize (hb_sanitize_context_t *c, const void *base) const
@ -171,8 +179,8 @@ struct feat
inline const FeatureName& get_feature (hb_aat_layout_feature_type_t key) const inline const FeatureName& get_feature (hb_aat_layout_feature_type_t key) const
{ {
const FeatureName* feature = (FeatureName*) hb_bsearch (&key, &namesZ, const FeatureName* feature = (FeatureName*) hb_bsearch (&key, &namesZ,
featureNameCount,
FeatureName::static_size, FeatureName::static_size,
sizeof (FeatureName),
FeatureName::cmp); FeatureName::cmp);
return feature ? *feature : Null (FeatureName); return feature ? *feature : Null (FeatureName);

View File

@ -967,7 +967,7 @@ struct Chain
flags &= feature.disableFlags; flags &= feature.disableFlags;
flags |= feature.enableFlags; flags |= feature.enableFlags;
} }
else if (type == HB_AAT_LAYOUT_FEATURE_TYPE_LETTER_CASE && setting == 3/*kSmallCapsSelector*/) else if (type == HB_AAT_LAYOUT_FEATURE_TYPE_LETTER_CASE && setting == HB_AAT_LAYOUT_SELECTOR_SMALL_CAPS)
{ {
/* Deprecated. https://github.com/harfbuzz/harfbuzz/issues/1342 */ /* Deprecated. https://github.com/harfbuzz/harfbuzz/issues/1342 */
type = HB_AAT_LAYOUT_FEATURE_TYPE_LOWER_CASE; type = HB_AAT_LAYOUT_FEATURE_TYPE_LOWER_CASE;

View File

@ -48,6 +48,8 @@
#include "hb-ot.h" #include "hb-ot.h"
#define HB_OT_H_IN #define HB_OT_H_IN
#include "hb-aat.h"
#include <math.h> #include <math.h>
#include <stdlib.h> #include <stdlib.h>
#include <stddef.h> #include <stddef.h>