Rename search() to bsearch() and lsearch()

Such that the complexity of the algorithm used is clear at
call site.
This commit is contained in:
Behdad Esfahbod 2014-06-19 15:39:18 -04:00
parent fb8cc86ff9
commit df554af99d
3 changed files with 14 additions and 13 deletions

View File

@ -837,7 +837,7 @@ struct GenericArrayOf
}
template <typename SearchType>
inline int search (const SearchType &x) const
inline int lsearch (const SearchType &x) const
{
unsigned int count = len;
for (unsigned int i = 0; i < count; i++)
@ -962,7 +962,7 @@ template <typename LenType, typename Type>
struct GenericSortedArrayOf : GenericArrayOf<LenType, Type>
{
template <typename SearchType>
inline int search (const SearchType &x) const
inline int bsearch (const SearchType &x) const
{
/* Hand-coded bsearch here since this is in the hot inner loop. */
int min = 0, max = (int) this->len - 1;

View File

@ -92,7 +92,7 @@ struct CmapSubtableFormat4
glyphIdArray = idRangeOffset + segCount;
glyphIdArrayLength = (this->length - 16 - 8 * segCount) / 2;
/* Custom bsearch. */
/* Custom two-array bsearch. */
int min = 0, max = (int) segCount - 1;
unsigned int i;
while (min <= max)
@ -247,7 +247,7 @@ struct CmapSubtableLongSegmented
private:
inline bool get_glyph (hb_codepoint_t codepoint, hb_codepoint_t *glyph) const
{
int i = groups.search (codepoint);
int i = groups.bsearch (codepoint);
if (i == -1)
return false;
*glyph = T::group_get_glyph (groups[i], codepoint);
@ -367,7 +367,10 @@ struct cmap
key.platformID.set (platform_id);
key.encodingID.set (encoding_id);
int result = encodingRecord.search (key);
/* Note: We can use bsearch, but since it has no performance
* implications, we use lsearch and as such accept fonts with
* unsorted subtable list. */
int result = encodingRecord./*bsearch*/lsearch (key);
if (result == -1 || !encodingRecord[result].subtable)
return NULL;
@ -382,10 +385,7 @@ struct cmap
}
USHORT version; /* Table version number (0). */
/* Note: We can use the Sorted array variant, but since it
* has no performance implications, we use non-sorted array and
* as such accept fonts with unsorted subtable list. */
/*Sorted*/ArrayOf<EncodingRecord>
SortedArrayOf<EncodingRecord>
encodingRecord; /* Encoding tables. */
public:
DEFINE_SIZE_ARRAY (4, encodingRecord);

View File

@ -103,7 +103,8 @@ struct RecordArrayOf : SortedArrayOf<Record<Type> > {
}
inline bool find_index (hb_tag_t tag, unsigned int *index) const
{
int i = this->search (tag);
/* If we want to allow non-sorted data, we can lsearch(). */
int i = this->/*lsearch*/bsearch (tag);
if (i != -1) {
if (index) *index = i;
return true;
@ -631,7 +632,7 @@ struct CoverageFormat1
private:
inline unsigned int get_coverage (hb_codepoint_t glyph_id) const
{
int i = glyphArray.search (glyph_id);
int i = glyphArray.bsearch (glyph_id);
ASSERT_STATIC (((unsigned int) -1) == NOT_COVERED);
return i;
}
@ -696,7 +697,7 @@ struct CoverageFormat2
private:
inline unsigned int get_coverage (hb_codepoint_t glyph_id) const
{
int i = rangeRecord.search (glyph_id);
int i = rangeRecord.bsearch (glyph_id);
if (i != -1) {
const RangeRecord &range = rangeRecord[i];
return (unsigned int) range.value + (glyph_id - range.start);
@ -992,7 +993,7 @@ struct ClassDefFormat2
private:
inline unsigned int get_class (hb_codepoint_t glyph_id) const
{
int i = rangeRecord.search (glyph_id);
int i = rangeRecord.bsearch (glyph_id);
if (i != -1)
return rangeRecord[i].value;
return 0;