[git commit] volume_id: code shrink

Denys Vlasenko vda.linux at googlemail.com
Sun Sep 2 13:33:47 UTC 2012


commit: http://git.busybox.net/busybox/commit/?id=8019b3a7aea51343f79922928c91ef833344b743
branch: http://git.busybox.net/busybox/commit/?id=refs/heads/master

function                                             old     new   delta
volume_id_set_unicode16                              200     173     -27

Signed-off-by: Denys Vlasenko <vda.linux at googlemail.com>
---
 util-linux/volume_id/util.c |   34 +++++++++++++++++++---------------
 1 files changed, 19 insertions(+), 15 deletions(-)

diff --git a/util-linux/volume_id/util.c b/util-linux/volume_id/util.c
index dd75c7b..69e43dd 100644
--- a/util-linux/volume_id/util.c
+++ b/util-linux/volume_id/util.c
@@ -31,25 +31,29 @@ void volume_id_set_unicode16(char *str, size_t len, const uint8_t *buf, enum end
 			c = (buf[i+1] << 8) | buf[i];
 		else
 			c = (buf[i] << 8) | buf[i+1];
-		if (c == 0) {
-			str[j] = '\0';
+		if (c == 0)
 			break;
-		} else if (c < 0x80) {
-			if (j+1 >= len)
-				break;
-			str[j++] = (uint8_t) c;
-		} else if (c < 0x800) {
-			if (j+2 >= len)
-				break;
-			str[j++] = (uint8_t) (0xc0 | (c >> 6));
-			str[j++] = (uint8_t) (0x80 | (c & 0x3f));
+		if (j+1 >= len)
+			break;
+		if (c < 0x80) {
+			/* 0xxxxxxx */
 		} else {
-			if (j+3 >= len)
+			uint8_t topbits = 0xc0;
+			if (j+2 >= len)
 				break;
-			str[j++] = (uint8_t) (0xe0 | (c >> 12));
-			str[j++] = (uint8_t) (0x80 | ((c >> 6) & 0x3f));
-			str[j++] = (uint8_t) (0x80 | (c & 0x3f));
+			if (c < 0x800) {
+				/* 110yyyxx 10xxxxxx */
+			} else {
+				if (j+3 >= len)
+					break;
+				/* 1110yyyy 10yyyyxx 10xxxxxx */
+				str[j++] = (uint8_t) (0xe0 | (c >> 12));
+				topbits = 0x80;
+			}
+			str[j++] = (uint8_t) (topbits | ((c >> 6) & 0x3f));
+			c = 0x80 | (c & 0x3f);
 		}
+		str[j++] = (uint8_t) c;
 	}
 	str[j] = '\0';
 }


More information about the busybox-cvs mailing list