All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Vladimir 'φ-coder/phcoder' Serbinenko" <phcoder@gmail.com>
To: The development of GRUB 2 <grub-devel@gnu.org>
Subject: [PATCH] Faster glyph lookup by BMP index
Date: Sun, 29 Nov 2009 15:29:18 +0100	[thread overview]
Message-ID: <4B12853E.70001@gmail.com> (raw)


[-- Attachment #1.1: Type: text/plain, Size: 417 bytes --]

Hello. Basic Multilingual Plane is range of Unicode characters in
0-65535 and it contains most of the characters needed by most of the
languages of the world. By keeping an array with pointers to such
characters at the cost of 128KiB per font we can almost instantenously
lookup characters which are likely to be used in grub. Available in
experimental

-- 
Regards
Vladimir 'φ-coder/phcoder' Serbinenko


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1.2: bmpidx.diff --]
[-- Type: text/x-diff; name="bmpidx.diff", Size: 2659 bytes --]

=== added file 'ChangeLog.bmpidx'
--- ChangeLog.bmpidx	1970-01-01 00:00:00 +0000
+++ ChangeLog.bmpidx	2009-11-29 14:17:03 +0000
@@ -0,0 +1,9 @@
+2009-11-29  Vladimir Serbinenko  <phcoder@gmail.com>
+
+	Optimise glyph lookup by Basic Multilingual Plane lookup array.
+
+	* font/font.c (struct grub_font): New member 'bmp_idx'.
+	(font_init): Initialise 'bmp_idx'.
+	(load_font_index): Fill 'bmp_idx'.
+	(find_glyph): Make inline. Use bmp_idx for BMP characters.
+

=== modified file 'font/font.c'
--- font/font.c	2009-07-20 17:37:37 +0000
+++ font/font.c	2009-11-29 13:24:58 +0000
@@ -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_
                                   * 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_
           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_in
 
 /* 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
   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;
 


[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 293 bytes --]

             reply	other threads:[~2009-11-29 14:29 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-11-29 14:29 Vladimir 'φ-coder/phcoder' Serbinenko [this message]
2009-11-29 16:24 ` [PATCH] Faster glyph lookup by BMP index richardvoigt
2009-11-29 16:28   ` Vladimir 'φ-coder/phcoder' Serbinenko
2009-12-04 21:13 ` Robert Millan

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=4B12853E.70001@gmail.com \
    --to=phcoder@gmail.com \
    --cc=grub-devel@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.