dcavalca / rpms / grub2

Forked from rpms/grub2 3 years ago
Clone

Blame SOURCES/0424-Speed-up-gfxterm-by-slightly-agglomerating-mallocs.patch

f96e0b
From b6fba8115cc492d54f185f37080817b05871785f Mon Sep 17 00:00:00 2001
f96e0b
From: Vladimir 'phcoder' Serbinenko <phcoder@gmail.com>
f96e0b
Date: Sat, 4 May 2013 15:07:13 +0200
f96e0b
Subject: [PATCH 424/482] 	Speed-up gfxterm by slightly agglomerating
f96e0b
 mallocs.
f96e0b
f96e0b
---
f96e0b
 ChangeLog                |  4 ++++
f96e0b
 grub-core/term/gfxterm.c | 61 ++++++++++++++----------------------------------
f96e0b
 include/grub/unicode.h   | 24 +++++++++++++++++++
f96e0b
 3 files changed, 45 insertions(+), 44 deletions(-)
f96e0b
f96e0b
diff --git a/ChangeLog b/ChangeLog
f96e0b
index a13face..963792e 100644
f96e0b
--- a/ChangeLog
f96e0b
+++ b/ChangeLog
f96e0b
@@ -1,5 +1,9 @@
f96e0b
 2013-05-04  Vladimir Serbinenko  <phcoder@gmail.com>
f96e0b
 
f96e0b
+	Speed-up gfxterm by slightly agglomerating mallocs.
f96e0b
+
f96e0b
+2013-05-04  Vladimir Serbinenko  <phcoder@gmail.com>
f96e0b
+
f96e0b
 	More video checks.
f96e0b
 
f96e0b
 2013-05-04  Vladimir Serbinenko  <phcoder@gmail.com>
f96e0b
diff --git a/grub-core/term/gfxterm.c b/grub-core/term/gfxterm.c
f96e0b
index 54636d7..0cb4037 100644
f96e0b
--- a/grub-core/term/gfxterm.c
f96e0b
+++ b/grub-core/term/gfxterm.c
f96e0b
@@ -49,7 +49,7 @@ struct grub_dirty_region
f96e0b
 struct grub_colored_char
f96e0b
 {
f96e0b
   /* An Unicode codepoint.  */
f96e0b
-  struct grub_unicode_glyph *code;
f96e0b
+  struct grub_unicode_glyph code;
f96e0b
 
f96e0b
   /* Color values.  */
f96e0b
   grub_video_color_t fg_color;
f96e0b
@@ -175,14 +175,8 @@ set_term_color (grub_uint8_t term_color)
f96e0b
 static void
f96e0b
 clear_char (struct grub_colored_char *c)
f96e0b
 {
f96e0b
-  if (c->code)
f96e0b
-    {
f96e0b
-      grub_free (c->code->combining);
f96e0b
-      grub_free (c->code);
f96e0b
-    }
f96e0b
-  c->code = grub_unicode_glyph_from_code (' ');
f96e0b
-  if (!c->code)
f96e0b
-    grub_errno = GRUB_ERR_NONE;
f96e0b
+  grub_free (c->code.combining);
f96e0b
+  grub_unicode_set_glyph_from_code (&c->code, ' ');
f96e0b
   c->fg_color = virtual_screen.fg_color;
f96e0b
   c->bg_color = virtual_screen.bg_color;
f96e0b
 }
f96e0b
@@ -197,11 +191,7 @@ grub_virtual_screen_free (void)
f96e0b
       for (i = 0;
f96e0b
 	   i < virtual_screen.columns * virtual_screen.rows;
f96e0b
 	   i++)
f96e0b
-	if (virtual_screen.text_buffer[i].code)
f96e0b
-	  {
f96e0b
-	    grub_free (virtual_screen.text_buffer[i].code->combining);
f96e0b
-	    grub_free (virtual_screen.text_buffer[i].code);
f96e0b
-	  }
f96e0b
+	grub_free (virtual_screen.text_buffer[i].code.combining);
f96e0b
       grub_free (virtual_screen.text_buffer);
f96e0b
     }
f96e0b
 
f96e0b
@@ -277,7 +267,7 @@ grub_virtual_screen_setup (unsigned int x, unsigned int y,
f96e0b
   /* Clear out text buffer. */
f96e0b
   for (i = 0; i < virtual_screen.columns * virtual_screen.rows; i++)
f96e0b
     {
f96e0b
-      virtual_screen.text_buffer[i].code = 0;
f96e0b
+      virtual_screen.text_buffer[i].code.combining = 0;
f96e0b
       clear_char (&(virtual_screen.text_buffer[i]));
f96e0b
     }
f96e0b
 
f96e0b
@@ -418,12 +408,9 @@ grub_gfxterm_term_fini (struct grub_term_output *term __attribute__ ((unused)))
f96e0b
 
f96e0b
   for (i = 0; i < virtual_screen.columns * virtual_screen.rows; i++)
f96e0b
     {
f96e0b
-      if (virtual_screen.text_buffer[i].code)
f96e0b
-	{
f96e0b
-	  grub_free (virtual_screen.text_buffer[i].code->combining);
f96e0b
-	  grub_free (virtual_screen.text_buffer[i].code);
f96e0b
-	}
f96e0b
-      virtual_screen.text_buffer[i].code = 0;
f96e0b
+      grub_free (virtual_screen.text_buffer[i].code.combining);
f96e0b
+      virtual_screen.text_buffer[i].code.combining = 0;
f96e0b
+      virtual_screen.text_buffer[i].code.base = 0;
f96e0b
     }
f96e0b
 
f96e0b
   /* Clear error state.  */
f96e0b
@@ -634,11 +621,11 @@ paint_char (unsigned cx, unsigned cy)
f96e0b
   p = (virtual_screen.text_buffer
f96e0b
        + cx + (cy * virtual_screen.columns));
f96e0b
 
f96e0b
-  if (!p->code)
f96e0b
+  if (!p->code.base)
f96e0b
     return;
f96e0b
 
f96e0b
   /* Get glyph for character.  */
f96e0b
-  glyph = grub_font_construct_glyph (virtual_screen.font, p->code);
f96e0b
+  glyph = grub_font_construct_glyph (virtual_screen.font, &p->code);
f96e0b
   if (!glyph)
f96e0b
     {
f96e0b
       grub_errno = GRUB_ERR_NONE;
f96e0b
@@ -817,11 +804,7 @@ scroll_up (void)
f96e0b
 
f96e0b
   /* Clear first line in text buffer.  */
f96e0b
   for (i = 0; i < virtual_screen.columns; i++)
f96e0b
-    if (virtual_screen.text_buffer[i].code)
f96e0b
-      {
f96e0b
-	grub_free (virtual_screen.text_buffer[i].code->combining);
f96e0b
-	grub_free (virtual_screen.text_buffer[i].code);
f96e0b
-      }
f96e0b
+    grub_free (virtual_screen.text_buffer[i].code.combining);
f96e0b
 
f96e0b
   /* Scroll text buffer with one line to up.  */
f96e0b
   grub_memmove (virtual_screen.text_buffer,
f96e0b
@@ -834,10 +817,7 @@ scroll_up (void)
f96e0b
   for (i = virtual_screen.columns * (virtual_screen.rows - 1);
f96e0b
        i < virtual_screen.columns * virtual_screen.rows;
f96e0b
        i++)
f96e0b
-    {
f96e0b
-      virtual_screen.text_buffer[i].code = 0;
f96e0b
-      clear_char (&(virtual_screen.text_buffer[i]));
f96e0b
-    }
f96e0b
+    clear_char (&(virtual_screen.text_buffer[i]));
f96e0b
 
f96e0b
   virtual_screen.total_scroll++;
f96e0b
 }
f96e0b
@@ -897,14 +877,9 @@ grub_gfxterm_putchar (struct grub_term_output *term,
f96e0b
       p = (virtual_screen.text_buffer +
f96e0b
            virtual_screen.cursor_x +
f96e0b
            virtual_screen.cursor_y * virtual_screen.columns);
f96e0b
-      if (p->code)
f96e0b
-	{
f96e0b
-	  grub_free (p->code->combining);
f96e0b
-	  grub_free (p->code);
f96e0b
-	}
f96e0b
-      p->code = grub_unicode_glyph_dup (c);
f96e0b
-      if (!p->code)
f96e0b
-	grub_errno = GRUB_ERR_NONE;
f96e0b
+      grub_free (p->code.combining);
f96e0b
+      grub_unicode_set_glyph (&p->code, c);
f96e0b
+      grub_errno = GRUB_ERR_NONE;
f96e0b
       p->fg_color = virtual_screen.fg_color;
f96e0b
       p->bg_color = virtual_screen.bg_color;
f96e0b
 
f96e0b
@@ -916,11 +891,9 @@ grub_gfxterm_putchar (struct grub_term_output *term,
f96e0b
           for (i = 1; i < char_width && p + i < 
f96e0b
 		 virtual_screen.text_buffer + virtual_screen.columns
f96e0b
 		 * virtual_screen.rows; i++)
f96e0b
-	    if (p[i].code)
f96e0b
 	      {
f96e0b
-		grub_free (p[i].code->combining);
f96e0b
-		grub_free (p[i].code);
f96e0b
-		p[i].code = NULL;
f96e0b
+		grub_free (p[i].code.combining);
f96e0b
+		p[i].code.base = 0;
f96e0b
 	      }
f96e0b
         }
f96e0b
 
f96e0b
diff --git a/include/grub/unicode.h b/include/grub/unicode.h
f96e0b
index 5a96a19..3d79c4c 100644
f96e0b
--- a/include/grub/unicode.h
f96e0b
+++ b/include/grub/unicode.h
f96e0b
@@ -274,6 +274,21 @@ grub_unicode_glyph_dup (const struct grub_unicode_glyph *in)
f96e0b
   return out;
f96e0b
 }
f96e0b
 
f96e0b
+static inline void
f96e0b
+grub_unicode_set_glyph (struct grub_unicode_glyph *out,
f96e0b
+			const struct grub_unicode_glyph *in)
f96e0b
+{
f96e0b
+  grub_memcpy (out, in, sizeof (*in));
f96e0b
+  if (in->combining)
f96e0b
+    {
f96e0b
+      out->combining = grub_malloc (in->ncomb * sizeof (out->combining[0]));
f96e0b
+      if (!out->combining)
f96e0b
+	return;
f96e0b
+      grub_memcpy (out->combining, in->combining,
f96e0b
+		   in->ncomb * sizeof (out->combining[0]));
f96e0b
+    }
f96e0b
+}
f96e0b
+
f96e0b
 static inline struct grub_unicode_glyph *
f96e0b
 grub_unicode_glyph_from_code (grub_uint32_t code)
f96e0b
 {
f96e0b
@@ -287,6 +302,15 @@ grub_unicode_glyph_from_code (grub_uint32_t code)
f96e0b
   return ret;
f96e0b
 }
f96e0b
 
f96e0b
+static inline void
f96e0b
+grub_unicode_set_glyph_from_code (struct grub_unicode_glyph *glyph,
f96e0b
+				  grub_uint32_t code)
f96e0b
+{
f96e0b
+  grub_memset (glyph, 0, sizeof (*glyph));
f96e0b
+
f96e0b
+  glyph->base = code;
f96e0b
+}
f96e0b
+
f96e0b
 grub_uint32_t
f96e0b
 grub_unicode_mirror_code (grub_uint32_t in);
f96e0b
 grub_uint32_t
f96e0b
-- 
f96e0b
1.8.2.1
f96e0b