Simplify logic for ensuring minimum hex length in rctocpp
authorAditya Mandaleeka <adityam@microsoft.com>
Tue, 19 May 2015 19:19:28 +0000 (12:19 -0700)
committerAditya Mandaleeka <adityam@microsoft.com>
Tue, 19 May 2015 19:19:28 +0000 (12:19 -0700)
Simplified the logic for ensuring that a hex string has 8 characters after
the '0x' prefix. Also clarified a comment about potential loss of numeric
precision when using numbers as indices in awk arrays.

src/dlls/mscorrc/rctocpp.awk

index c547bf7..84b4b90 100644 (file)
@@ -15,19 +15,13 @@ function numberToHexString(number)
     quotient = number;
 
     hexString = "";
-    while (quotient > 0)
+    for (digitCount = 0; digitCount < 8; digitCount++)
     {
         remainder = quotient % 16;
         quotient = int(quotient / 16);
         hexString = sprintf("%x"hexString, remainder);
     }
 
-    lengthOfHexString = length(hexString);
-    if (lengthOfHexString < 8)
-    {
-        hexString = substr("00000000", 1, 8 - lengthOfHexString) hexString;
-    }
-
     hexString = "0x" hexString;
     return hexString;
 }
@@ -56,8 +50,9 @@ function writestringentry(id, str)
     numEntries++;
 
     # Use the string representation of the ID as the array index
-    # because the precision of numeric indices can be lost when
-    # iterating over the array in our for-in loop.
+    # because the precision of numeric indices can be lost during
+    # the number -> string -> number conversions that would occur
+    # if numeric indices are used.
     resourceArray[numberToHexString(id)] = str;
 }