From owner-svn-src-all@FreeBSD.ORG Mon Jun 9 20:52:36 2014 Return-Path: Delivered-To: svn-src-all@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [8.8.178.115]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTPS id 6401643A; Mon, 9 Jun 2014 20:52:36 +0000 (UTC) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:1900:2254:2068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id 44B5821A8; Mon, 9 Jun 2014 20:52:36 +0000 (UTC) Received: from svn.freebsd.org ([127.0.1.70]) by svn.freebsd.org (8.14.8/8.14.8) with ESMTP id s59KqaCq029030; Mon, 9 Jun 2014 20:52:36 GMT (envelope-from emaste@svn.freebsd.org) Received: (from emaste@localhost) by svn.freebsd.org (8.14.8/8.14.8/Submit) id s59Kqaha029029; Mon, 9 Jun 2014 20:52:36 GMT (envelope-from emaste@svn.freebsd.org) Message-Id: <201406092052.s59Kqaha029029@svn.freebsd.org> From: Ed Maste Date: Mon, 9 Jun 2014 20:52:36 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r267301 - head/tools/tools/vt/fontcvt X-SVN-Group: head MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: "SVN commit messages for the entire src tree \(except for " user" and " projects" \)" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 09 Jun 2014 20:52:36 -0000 Author: emaste Date: Mon Jun 9 20:52:35 2014 New Revision: 267301 URL: http://svnweb.freebsd.org/changeset/base/267301 Log: vt fontcvt: Speed up bold glyph map deduplication Perform an O(n) deduplication pass over the bold maps at the end, rather than walking the normal map list to look for a duplicate glyph each time a bold mapping entry is added. Sponsored by: The FreeBSD Foundation Modified: head/tools/tools/vt/fontcvt/fontcvt.c Modified: head/tools/tools/vt/fontcvt/fontcvt.c ============================================================================== --- head/tools/tools/vt/fontcvt/fontcvt.c Mon Jun 9 20:51:08 2014 (r267300) +++ head/tools/tools/vt/fontcvt/fontcvt.c Mon Jun 9 20:52:35 2014 (r267301) @@ -37,6 +37,7 @@ __FBSDID("$FreeBSD$"); #include #include +#include #include #include #include @@ -45,7 +46,9 @@ __FBSDID("$FreeBSD$"); #define VFNT_MAPS 4 #define VFNT_MAP_NORMAL 0 +#define VFNT_MAP_NORMAL_RH 1 #define VFNT_MAP_BOLD 2 +#define VFNT_MAP_BOLD_RH 3 static unsigned int width = 8, wbytes, height = 16; @@ -101,34 +104,6 @@ add_mapping(struct glyph *gl, unsigned i mapping_total++; - if (map_idx >= VFNT_MAP_BOLD) { - int found = 0; - unsigned normal_map_idx = map_idx - VFNT_MAP_BOLD; - - TAILQ_FOREACH(mp, &maps[normal_map_idx], m_list) { - if (mp->m_char < c) - continue; - else if (mp->m_char > c) - break; - found = 1; - - /* - * No mapping is needed if it's equal to the - * normal mapping. - */ - if (mp->m_glyph == gl) { - mapping_dupe++; - return (0); - } - } - - if (!found) { - fprintf(stderr, - "Character %u not in normal font!\n", c); - return (1); - } - } - mp = malloc(sizeof *mp); mp->m_char = c; mp->m_glyph = gl; @@ -148,6 +123,33 @@ add_mapping(struct glyph *gl, unsigned i return (0); } +static int +dedup_mapping(unsigned int map_idx) +{ + struct mapping *mp_bold, *mp_normal, *mp_temp; + unsigned normal_map_idx = map_idx - VFNT_MAP_BOLD; + + assert(map_idx == VFNT_MAP_BOLD || map_idx == VFNT_MAP_BOLD_RH); + mp_normal = TAILQ_FIRST(&maps[normal_map_idx]); + TAILQ_FOREACH_SAFE(mp_bold, &maps[map_idx], m_list, mp_temp) { + while (mp_normal->m_char < mp_bold->m_char) + mp_normal = TAILQ_NEXT(mp_normal, m_list); + if (mp_bold->m_char != mp_normal->m_char) { + errx(1, "Character %u not in normal font!\n", + mp_bold->m_char); + return (1); + } + if (mp_bold->m_glyph != mp_normal->m_glyph) + continue; + + /* No mapping is needed if it's equal to the normal mapping. */ + TAILQ_REMOVE(&maps[map_idx], mp_bold, m_list); + free(mp_bold); + mapping_dupe++; + } + return (0); +} + static struct glyph * add_glyph(const uint8_t *bytes, unsigned int map_idx, int fallback) { @@ -540,6 +542,8 @@ main(int argc, char *argv[]) argv++; } number_glyphs(); + dedup_mapping(VFNT_MAP_BOLD); + dedup_mapping(VFNT_MAP_BOLD_RH); fold_mappings(0); fold_mappings(1); fold_mappings(2);