Index of BMP for faster font lookup

This commit is contained in:
Vladimir 'phcoder' Serbinenko 2009-11-29 14:26:07 +01:00
parent dc9837ea5f
commit f9e4ed6a45

View file

@ -58,6 +58,7 @@ struct grub_font
short leading;
grub_uint32_t num_chars;
struct char_index_entry *char_index;
grub_uint16_t *bmp_idx;
};
/* Definition of font registry. */
@ -180,6 +181,7 @@ font_init (grub_font_t font)
font->descent = 0;
font->num_chars = 0;
font->char_index = 0;
font->bmp_idx = 0;
}
/* Open the next section in the file.
@ -273,6 +275,14 @@ load_font_index (grub_file_t file, grub_uint32_t sect_length, struct
* sizeof (struct char_index_entry));
if (! font->char_index)
return 1;
font->bmp_idx = grub_malloc (0x10000 * sizeof (grub_uint16_t));
if (! font->bmp_idx)
{
grub_free (font->char_index);
return 1;
}
grub_memset (font->bmp_idx, 0xff, 0x10000 * sizeof (grub_uint16_t));
#if FONT_DEBUG >= 2
grub_printf("num_chars=%d)\n", font->num_chars);
@ -299,6 +309,9 @@ load_font_index (grub_file_t file, grub_uint32_t sect_length, struct
return 1;
}
if (entry->code < 0x10000)
font->bmp_idx[entry->code] = i;
last_code = entry->code;
/* Read storage flags byte. */
@ -594,7 +607,7 @@ read_be_int16 (grub_file_t file, grub_int16_t * value)
/* Return a pointer to the character index entry for the glyph corresponding to
the codepoint CODE in the font FONT. If not found, return zero. */
static struct char_index_entry *
static inline struct char_index_entry *
find_glyph (const grub_font_t font, grub_uint32_t code)
{
struct char_index_entry *table;
@ -602,8 +615,17 @@ find_glyph (const grub_font_t font, grub_uint32_t code)
grub_size_t hi;
grub_size_t mid;
/* Do a binary search in `char_index', which is ordered by code point. */
table = font->char_index;
/* Use BMP index if possible. */
if (code < 0x10000)
{
if (font->bmp_idx[code] == 0xffff)
return 0;
return &table[font->bmp_idx[code]];
}
/* Do a binary search in `char_index', which is ordered by code point. */
lo = 0;
hi = font->num_chars - 1;