From 0133cb55e2d76c81ccfeef3baf4c46e31297665c Mon Sep 17 00:00:00 2001 From: Ebrahim Byagowi Date: Sun, 19 Apr 2020 22:42:57 +0430 Subject: [PATCH] Minor, use hb_sorted_array::bsearch where possible --- src/hb-aat-layout.cc | 2 +- src/hb-ot-cff1-table.cc | 4 ++-- src/hb-ot-os2-unicode-ranges.hh | 7 +++---- 3 files changed, 6 insertions(+), 7 deletions(-) diff --git a/src/hb-aat-layout.cc b/src/hb-aat-layout.cc index 6d93f1efa..fa1048e18 100644 --- a/src/hb-aat-layout.cc +++ b/src/hb-aat-layout.cc @@ -172,7 +172,7 @@ static const hb_aat_feature_mapping_t feature_mappings[] = const hb_aat_feature_mapping_t * hb_aat_layout_find_feature_mapping (hb_tag_t tag) { - return hb_bsearch (tag, feature_mappings, ARRAY_LENGTH (feature_mappings)); + return hb_sorted_array (feature_mappings).bsearch (tag); } #endif diff --git a/src/hb-ot-cff1-table.cc b/src/hb-ot-cff1-table.cc index 6a5bac000..66b9c8c90 100644 --- a/src/hb-ot-cff1-table.cc +++ b/src/hb-ot-cff1-table.cc @@ -247,13 +247,13 @@ hb_codepoint_t OT::cff1::lookup_expert_subset_charset_for_sid (hb_codepoint_t gl hb_codepoint_t OT::cff1::lookup_expert_charset_for_glyph (hb_codepoint_t sid) { - const auto *pair = hb_bsearch (sid, expert_charset_sid_to_gid, ARRAY_LENGTH (expert_charset_sid_to_gid)); + const auto *pair = hb_sorted_array (expert_charset_sid_to_gid).bsearch (sid); return pair ? pair->gid : 0; } hb_codepoint_t OT::cff1::lookup_expert_subset_charset_for_glyph (hb_codepoint_t sid) { - const auto *pair = hb_bsearch (sid, expert_subset_charset_sid_to_gid, ARRAY_LENGTH (expert_subset_charset_sid_to_gid)); + const auto *pair = hb_sorted_array (expert_subset_charset_sid_to_gid).bsearch (sid); return pair ? pair->gid : 0; } diff --git a/src/hb-ot-os2-unicode-ranges.hh b/src/hb-ot-os2-unicode-ranges.hh index fd432edd6..a592e9663 100644 --- a/src/hb-ot-os2-unicode-ranges.hh +++ b/src/hb-ot-os2-unicode-ranges.hh @@ -222,10 +222,9 @@ static const OS2Range _hb_os2_unicode_ranges[] = static unsigned int _hb_ot_os2_get_unicode_range_bit (hb_codepoint_t cp) { - auto* range = hb_bsearch (cp, _hb_os2_unicode_ranges, ARRAY_LENGTH (_hb_os2_unicode_ranges)); - if (range != nullptr) - return range->bit; - return -1; + auto *range = hb_sorted_array (_hb_os2_unicode_ranges).bsearch (cp); + if (unlikely (range == nullptr)) return -1; + return range->bit; } } /* namespace OT */