Bug 1388789 - replace hex strings with static arrays; r?froydnj draft
authorTom Tromey <tom@tromey.com>
Fri, 01 Sep 2017 06:25:11 -0600
changeset 667044 0af0358198b80926a8196adc52d6931c49e1ae61
parent 667043 a4718aa876bfe428a5d7eec71279ceba10b3aac5
child 667045 f5e6bea7500e868e4f0afdd1adeea7aaad8de383
child 667148 6d5dc224f5d886d477746294f57e0fca2765214b
child 667174 5e8b4a10807102a20f6ad3f3469fb33bdb94234d
push id80599
push userbmo:ttromey@mozilla.com
push dateTue, 19 Sep 2017 16:49:35 +0000
reviewersfroydnj
bugs1388789
milestone57.0a1
Bug 1388789 - replace hex strings with static arrays; r?froydnj nsTextFormatter used nsAutoString for arrays of hex digits; but this didn't seem to provide any benefit. MozReview-Commit-ID: EYHtnAzJL8h
xpcom/string/nsTextFormatter.cpp
--- a/xpcom/string/nsTextFormatter.cpp
+++ b/xpcom/string/nsTextFormatter.cpp
@@ -828,21 +828,18 @@ dosprintf(SprintfStateStr* aState, const
     int64_t ll;
     double d;
     const char* s;
     const char16_t* S;
     int* ip;
   } u;
   char16_t space = ' ';
 
-  nsAutoString hex;
-  hex.AssignLiteral("0123456789abcdef");
-
-  nsAutoString HEX;
-  HEX.AssignLiteral("0123456789ABCDEF");
+  static const char16_t hex[] = u"0123456789abcdef";
+  static char16_t HEX[] = u"0123456789ABCDEF";
 
   const char16_t* hexp;
   int rv, i;
   struct NumArgState* nas = nullptr;
   struct NumArgState  nasArray[NAS_DEFAULT_NUM];
 
 
   /*
@@ -976,17 +973,17 @@ dosprintf(SprintfStateStr* aState, const
       c = *aFmt++;
       if (c == 'l') {
         type = NumArgState::INT64;
         c = *aFmt++;
       }
     }
 
     /* format */
-    hexp = hex.get();
+    hexp = hex;
     switch (c) {
       case 'd':
       case 'i':                               /* decimal/integer */
         radix = 10;
         goto fetch_and_convert;
 
       case 'o':                               /* octal */
         radix = 8;
@@ -1000,17 +997,17 @@ dosprintf(SprintfStateStr* aState, const
 
       case 'x':                               /* unsigned hex */
         radix = 16;
         type |= 1;
         goto fetch_and_convert;
 
       case 'X':                               /* unsigned HEX */
         radix = 16;
-        hexp = HEX.get();
+        hexp = HEX;
         type |= 1;
         goto fetch_and_convert;
 
         fetch_and_convert:
         switch (type) {
           case NumArgState::INT16:
             u.l = va_arg(aAp, int);
             if (u.l < 0) {