volume_id: uuid_format small code shrink
authorSven-Göran Bergh <sgb@systemasis.org>
Sun, 13 Jan 2013 23:50:49 +0000 (00:50 +0100)
committerDenys Vlasenko <vda.linux@googlemail.com>
Sun, 13 Jan 2013 23:52:03 +0000 (00:52 +0100)
function                                             old     new   delta
volume_id_set_uuid                                   318     300     -18

Signed-off-by: Sven-Göran Bergh <sgb@systemasis.org>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
util-linux/volume_id/util.c
util-linux/volume_id/volume_id_internal.h

index 11ee0d52ef7516a397f8c2ae98338aee3c88403c..0e2d24be04d57cc4feacf493495eedc692964b18 100644 (file)
@@ -135,23 +135,8 @@ void volume_id_set_label_unicode16(struct volume_id *id, const uint8_t *buf, enu
 void volume_id_set_uuid(struct volume_id *id, const uint8_t *buf, enum uuid_format format)
 {
        unsigned i;
-       unsigned count = 0;
+       unsigned count = (format == UUID_DCE_STRING ? VOLUME_ID_UUID_SIZE : 4 << format);
 
-       switch (format) {
-       case UUID_DOS:
-               count = 4;
-               break;
-       case UUID_NTFS:
-               count = 8;
-               break;
-       case UUID_DCE:
-               count = 16;
-               break;
-       case UUID_DCE_STRING:
-               /* 36 is ok, id->uuid has one extra byte for NUL */
-               count = VOLUME_ID_UUID_SIZE;
-               break;
-       }
 //     memcpy(id->uuid_raw, buf, count);
 //     id->uuid_raw_len = count;
 
index dd62df399d09f2d8f1c831673737fe3062930655..e26ebaab619870a7fca16ab78a422349c10daa85 100644 (file)
@@ -136,11 +136,15 @@ void FAST_FUNC free_volume_id(struct volume_id *id);
 #define cpu_to_be32(x) (x)
 #endif
 
+/* volume_id_set_uuid(id,buf,fmt) assumes size of uuid buf
+ * by shifting: 4 << fmt, except for fmt == UUID_DCE_STRING.
+ * The constants below should match sizes.
+ */
 enum uuid_format {
-       UUID_DCE_STRING,
-       UUID_DCE,
-       UUID_DOS,
-       UUID_NTFS,
+       UUID_DOS = 0,           /* 4 bytes */
+       UUID_NTFS = 1,          /* 8 bytes */
+       UUID_DCE = 2,           /* 16 bytes */
+       UUID_DCE_STRING = 3,    /* 36 bytes (VOLUME_ID_UUID_SIZE) */
 };
 
 enum endian {