]> git.proxmox.com Git - mirror_edk2.git/commitdiff
Refine code.
authorsfu5 <sfu5@6f19259b-4bc3-4df7-8a09-765794883524>
Mon, 16 Aug 2010 01:11:49 +0000 (01:11 +0000)
committersfu5 <sfu5@6f19259b-4bc3-4df7-8a09-765794883524>
Mon, 16 Aug 2010 01:11:49 +0000 (01:11 +0000)
git-svn-id: https://edk2.svn.sourceforge.net/svnroot/edk2/trunk/edk2@10799 6f19259b-4bc3-4df7-8a09-765794883524

MdePkg/Library/BaseLib/String.c

index 0b6a1957472fc169a59a741239cf7fe5c3372860..273291a915b281ce1eebeaa611b63074da2a9a24 100644 (file)
 \r
 #include "BaseLibInternals.h"\r
 \r
 \r
 #include "BaseLibInternals.h"\r
 \r
-#define QUOTIENT_MAX_UINTN_DIVIDED_BY_10      ((~((UINTN) 0)) / 10U)\r
-#define REMAINDER_MAX_UINTN_DIVIDED_BY_10    ((~((UINTN) 0)) % 10U)\r
-\r
-\r
-#define QUOTIENT_MAX_UINTN_DIVIDED_BY_16       ((~((UINTN) 0)) / 16U)\r
-#define REMAINDER_MAX_UINTN_DIVIDED_BY_16     ((~((UINTN) 0)) % 16U)\r
-\r
-#define QUOTIENT_MAX_UINT64_DIVIDED_BY_10      ((~((UINT64) 0)) / 10U)\r
-#define REMAINDER_MAX_UINT64_DIVIDED_BY_10    ((~((UINT64) 0)) % 10U)\r
-\r
-#define QUOTIENT_MAX_UINT64_DIVIDED_BY_16      ((~((UINT64) 0)) / 16U)\r
-#define REMAINDER_MAX_UINT64_DIVIDED_BY_16    ((~((UINT64) 0)) % 16U)\r
 \r
 /**\r
   Copies one Null-terminated Unicode string to another Null-terminated Unicode\r
 \r
 /**\r
   Copies one Null-terminated Unicode string to another Null-terminated Unicode\r
@@ -682,10 +670,7 @@ StrDecimalToUintn (
     // If the number represented by String overflows according \r
     // to the range defined by UINTN, then ASSERT().\r
     //\r
     // If the number represented by String overflows according \r
     // to the range defined by UINTN, then ASSERT().\r
     //\r
-    ASSERT ((Result < QUOTIENT_MAX_UINTN_DIVIDED_BY_10) ||\r
-      ((Result == QUOTIENT_MAX_UINTN_DIVIDED_BY_10) &&\r
-      (*String - L'0') <= REMAINDER_MAX_UINTN_DIVIDED_BY_10)\r
-      );\r
+    ASSERT (Result <= ((((UINTN) ~0) - (*String - L'0')) / 10));\r
 \r
     Result = Result * 10 + (*String - L'0');\r
     String++;\r
 \r
     Result = Result * 10 + (*String - L'0');\r
     String++;\r
@@ -764,10 +749,7 @@ StrDecimalToUint64 (
     // If the number represented by String overflows according \r
     // to the range defined by UINTN, then ASSERT().\r
     //\r
     // If the number represented by String overflows according \r
     // to the range defined by UINTN, then ASSERT().\r
     //\r
-    ASSERT ((Result < QUOTIENT_MAX_UINT64_DIVIDED_BY_10) || \r
-      ((Result == QUOTIENT_MAX_UINT64_DIVIDED_BY_10) && \r
-      (*String - L'0') <= REMAINDER_MAX_UINT64_DIVIDED_BY_10)\r
-      );\r
+    ASSERT (Result <= DivU64x32 (((UINT64) ~0) - (*String - L'0') , 10));\r
 \r
     Result = MultU64x32 (Result, 10) + (*String - L'0');\r
     String++;\r
 \r
     Result = MultU64x32 (Result, 10) + (*String - L'0');\r
     String++;\r
@@ -856,10 +838,7 @@ StrHexToUintn (
     // If the Hex Number represented by String overflows according \r
     // to the range defined by UINTN, then ASSERT().\r
     //\r
     // If the Hex Number represented by String overflows according \r
     // to the range defined by UINTN, then ASSERT().\r
     //\r
-    ASSERT ((Result < QUOTIENT_MAX_UINTN_DIVIDED_BY_16) ||\r
-      ((Result == QUOTIENT_MAX_UINTN_DIVIDED_BY_16) && \r
-      (InternalHexCharToUintn (*String) <= REMAINDER_MAX_UINTN_DIVIDED_BY_16))\r
-      );\r
+    ASSERT (Result <= ((((UINTN) ~0) - InternalHexCharToUintn (*String)) >> 4));\r
 \r
     Result = (Result << 4) + InternalHexCharToUintn (*String);\r
     String++;\r
 \r
     Result = (Result << 4) + InternalHexCharToUintn (*String);\r
     String++;\r
@@ -950,10 +929,7 @@ StrHexToUint64 (
     // If the Hex Number represented by String overflows according \r
     // to the range defined by UINTN, then ASSERT().\r
     //\r
     // If the Hex Number represented by String overflows according \r
     // to the range defined by UINTN, then ASSERT().\r
     //\r
-    ASSERT ((Result < QUOTIENT_MAX_UINT64_DIVIDED_BY_16)|| \r
-      ((Result == QUOTIENT_MAX_UINT64_DIVIDED_BY_16) && \r
-      (InternalHexCharToUintn (*String) <= REMAINDER_MAX_UINT64_DIVIDED_BY_16))\r
-      );\r
+    ASSERT (Result <= RShiftU64 (((UINT64) ~0) - InternalHexCharToUintn (*String) , 4));\r
 \r
     Result = LShiftU64 (Result, 4);\r
     Result = Result + InternalHexCharToUintn (*String);\r
 \r
     Result = LShiftU64 (Result, 4);\r
     Result = Result + InternalHexCharToUintn (*String);\r
@@ -1717,10 +1693,7 @@ AsciiStrDecimalToUintn (
     // If the number represented by String overflows according \r
     // to the range defined by UINTN, then ASSERT().\r
     //\r
     // If the number represented by String overflows according \r
     // to the range defined by UINTN, then ASSERT().\r
     //\r
-    ASSERT ((Result < QUOTIENT_MAX_UINTN_DIVIDED_BY_10) ||\r
-      ((Result == QUOTIENT_MAX_UINTN_DIVIDED_BY_10) && \r
-      (*String - '0') <= REMAINDER_MAX_UINTN_DIVIDED_BY_10)\r
-      );\r
+    ASSERT (Result <= ((((UINTN) ~0) - (*String - L'0')) / 10));\r
 \r
     Result = Result * 10 + (*String - '0');\r
     String++;\r
 \r
     Result = Result * 10 + (*String - '0');\r
     String++;\r
@@ -1794,10 +1767,7 @@ AsciiStrDecimalToUint64 (
     // If the number represented by String overflows according \r
     // to the range defined by UINTN, then ASSERT().\r
     //\r
     // If the number represented by String overflows according \r
     // to the range defined by UINTN, then ASSERT().\r
     //\r
-    ASSERT ((Result < QUOTIENT_MAX_UINT64_DIVIDED_BY_10) || \r
-      ((Result == QUOTIENT_MAX_UINT64_DIVIDED_BY_10) && \r
-      (*String - '0') <= REMAINDER_MAX_UINT64_DIVIDED_BY_10)\r
-      );\r
+    ASSERT (Result <= DivU64x32 (((UINT64) ~0) - (*String - L'0') , 10));\r
 \r
     Result = MultU64x32 (Result, 10) + (*String - '0');\r
     String++;\r
 \r
     Result = MultU64x32 (Result, 10) + (*String - '0');\r
     String++;\r
@@ -1885,10 +1855,7 @@ AsciiStrHexToUintn (
     // If the Hex Number represented by String overflows according \r
     // to the range defined by UINTN, then ASSERT().\r
     //\r
     // If the Hex Number represented by String overflows according \r
     // to the range defined by UINTN, then ASSERT().\r
     //\r
-     ASSERT ((Result < QUOTIENT_MAX_UINTN_DIVIDED_BY_16) ||\r
-       ((Result == QUOTIENT_MAX_UINTN_DIVIDED_BY_16) && \r
-       (InternalAsciiHexCharToUintn (*String) <= REMAINDER_MAX_UINTN_DIVIDED_BY_16))\r
-       );\r
+    ASSERT (Result <= ((((UINTN) ~0) - InternalHexCharToUintn (*String)) >> 4));\r
 \r
     Result = (Result << 4) + InternalAsciiHexCharToUintn (*String);\r
     String++;\r
 \r
     Result = (Result << 4) + InternalAsciiHexCharToUintn (*String);\r
     String++;\r
@@ -1980,10 +1947,7 @@ AsciiStrHexToUint64 (
     // If the Hex Number represented by String overflows according \r
     // to the range defined by UINTN, then ASSERT().\r
     //\r
     // If the Hex Number represented by String overflows according \r
     // to the range defined by UINTN, then ASSERT().\r
     //\r
-    ASSERT ((Result < QUOTIENT_MAX_UINT64_DIVIDED_BY_16) ||\r
-      ((Result == QUOTIENT_MAX_UINT64_DIVIDED_BY_16) && \r
-      (InternalAsciiHexCharToUintn (*String) <= REMAINDER_MAX_UINT64_DIVIDED_BY_16))\r
-      );\r
+    ASSERT (Result <= RShiftU64 (((UINT64) ~0) - InternalHexCharToUintn (*String) , 4));\r
 \r
     Result = LShiftU64 (Result, 4);\r
     Result = Result + InternalAsciiHexCharToUintn (*String);\r
 \r
     Result = LShiftU64 (Result, 4);\r
     Result = Result + InternalAsciiHexCharToUintn (*String);\r