svn commit: r199971 - user/ed/newcons/sys/dev/vt

Ed Schouten ed at FreeBSD.org
Mon Nov 30 18:48:08 UTC 2009


Author: ed
Date: Mon Nov 30 18:48:07 2009
New Revision: 199971
URL: http://svn.freebsd.org/changeset/base/199971

Log:
  Optimize vtfont_bisearch() for the common case (ASCII).
  
  More than 90% of the time we'll probably just display ASCII characters.
  In almost all cases this is stored in entry 0 of the map, so validate
  the first map by hand.

Modified:
  user/ed/newcons/sys/dev/vt/vt_font.c

Modified: user/ed/newcons/sys/dev/vt/vt_font.c
==============================================================================
--- user/ed/newcons/sys/dev/vt/vt_font.c	Mon Nov 30 18:26:46 2009	(r199970)
+++ user/ed/newcons/sys/dev/vt/vt_font.c	Mon Nov 30 18:48:07 2009	(r199971)
@@ -53,10 +53,20 @@ vtfont_bisearch(const struct vt_font_map
 	min = 0;
 	max = len - 1;
 
-	if (len == 0 || src < map[0].vfm_src ||
-	    src > map[max].vfm_src + map[max].vfm_len)
+	/* Empty font map. */
+	if (len == 0)
+		return (0);
+	/* Character below minimal entry. */
+	if (src < map[0].vfm_src)
+		return (0);
+	/* Optimization: ASCII characters occur very often. */
+	if (src <= map[0].vfm_src + map[0].vfm_len)
+		return (src - map[0].vfm_src + map[0].vfm_dst);
+	/* Character above maximum entry. */
+	if (src > map[max].vfm_src + map[max].vfm_len)
 		return (0);
 
+	/* Binary search. */
 	while (max >= min) {
 		mid = (min + max) / 2;
 		if (src < map[mid].vfm_src)


More information about the svn-src-user mailing list