Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 3 Sep 2019 16:15:57 +0000 (UTC)
From:      Ed Maste <emaste@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-12@freebsd.org
Subject:   svn commit: r351749 - stable/12/usr.bin/vtfontcvt
Message-ID:  <201909031615.x83GFvZT034744@repo.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: emaste
Date: Tue Sep  3 16:15:57 2019
New Revision: 351749
URL: https://svnweb.freebsd.org/changeset/base/351749

Log:
  MFC r351425: vtfontcvt: simplify rshift_row
  
  We don't need to specify the buffer size in both bytes and bits.
  
  Sponsored by:	The FreeBSD Foundation

Modified:
  stable/12/usr.bin/vtfontcvt/vtfontcvt.c
Directory Properties:
  stable/12/   (props changed)

Modified: stable/12/usr.bin/vtfontcvt/vtfontcvt.c
==============================================================================
--- stable/12/usr.bin/vtfontcvt/vtfontcvt.c	Tue Sep  3 15:42:11 2019	(r351748)
+++ stable/12/usr.bin/vtfontcvt/vtfontcvt.c	Tue Sep  3 16:15:57 2019	(r351749)
@@ -224,38 +224,19 @@ add_char(unsigned curchar, unsigned map_idx, uint8_t *
 }
 
 /*
- * Right-shift glyph row by _shift_ bits. Row _len_ bits wide, _size_ bytes.
+ * Right-shift glyph row.
  */
-static int
-rshift_row(uint8_t *line, size_t size, size_t len, size_t shift)
+static void
+rshift_row(uint8_t *buf, size_t len, size_t shift)
 {
-	size_t d, s, i;
-	uint16_t t;
+	ssize_t i, off_byte = shift / 8;
+	size_t off_bit = shift % 8;
 
-	assert(size > 0 && len > 0);
-	assert(size * 8 >= len);
-
 	if (shift == 0)
-		return (0);
-
-	d = shift / 8;
-	s = 8 - shift % 8;
-	i = howmany(len, 8);
-
-	while (i > 0) {
-		i--;
-
-		t = *(line + i);
-		*(line + i) = 0;
-
-		t <<= s;
-
-		if (i + d + 1 < size)
-			*(line + i + d + 1) |= (uint8_t)t;
-		if (i + d < size)
-			*(line + i + d) = t >> 8;
-	}
-	return (0);
+		return;
+	for (i = len - 1; i >= 0; i--)
+		buf[i] = (i >= off_byte ? buf[i - off_byte] >> off_bit : 0) |
+		    (i > off_byte ? buf[i - off_byte - 1] << (8 - off_bit) : 0);
 }
 
 /*
@@ -426,11 +407,7 @@ parse_bdf(FILE *fp, unsigned int map_idx)
 					*(line + j) = (uint8_t)val;
 				}
 
-				rv = rshift_row(line, wbytes * 2, bbw,
-				    bbox - fbbox);
-				if (rv != 0)
-					goto out;
-
+				rshift_row(line, wbytes * 2, bbox - fbbox);
 				rv = split_row(bytes + i * wbytes,
 				     bytes_r + i * wbytes, line, dwidth);
 				if (rv != 0)



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201909031615.x83GFvZT034744>