Bug 1411480 - Inline and remove the parser's pref_DoCallback() function. r=glandium.
☠☠ backed out by 3c6a28afa74b ☠ ☠
authorNicholas Nethercote <nnethercote@mozilla.com>
Wed, 25 Oct 2017 10:22:38 +1100
changeset 430891 f1cf84a50ebc368ad4e2088957cbda008a74520d
parent 430890 c2bdce9b76f2135fd100f073b6ccaf8bb9a69fed
child 430892 e87ba9542cf8bac95d16545dfd129f5a39d56a22
push id108
push userfmarier@mozilla.com
push dateFri, 03 Nov 2017 18:37:44 +0000
reviewersglandium
bugs1411480
milestone58.0a1
Bug 1411480 - Inline and remove the parser's pref_DoCallback() function. r=glandium. Preferences.cpp has two functions named pref_DoCallback(). One of them has a single use in the parser. This patch inlines that single use to remove the name duplication. MozReview-Commit-ID: HnyteQ0N5M1
modules/libpref/Preferences.cpp
--- a/modules/libpref/Preferences.cpp
+++ b/modules/libpref/Preferences.cpp
@@ -1494,59 +1494,16 @@ pref_ReportParseProblem(PrefParseState& 
   } else {
     printf_stderr("**** Preference parsing %s (line %d) = %s **\n",
                   (aError ? "error" : "warning"),
                   aLine,
                   aMessage);
   }
 }
 
-// This function is called when a complete pref name-value pair has been
-// extracted from the input data.
-//
-// @param aPS
-//        parse state instance
-//
-// @return false to indicate a fatal error.
-static bool
-pref_DoCallback(PrefParseState* aPS)
-{
-  PrefValue value;
-
-  switch (aPS->mVtype) {
-    case PrefType::String:
-      value.mStringVal = aPS->mVb;
-      break;
-
-    case PrefType::Int:
-      if ((aPS->mVb[0] == '-' || aPS->mVb[0] == '+') && aPS->mVb[1] == '\0') {
-        pref_ReportParseProblem(*aPS, "invalid integer value", 0, true);
-        NS_WARNING("malformed integer value");
-        return false;
-      }
-      value.mIntVal = atoi(aPS->mVb);
-      break;
-
-    case PrefType::Bool:
-      value.mBoolVal = (aPS->mVb == kTrue);
-      break;
-
-    default:
-      break;
-  }
-
-  (*aPS->mReader)(aPS->mClosure,
-                  aPS->mLb,
-                  value,
-                  aPS->mVtype,
-                  aPS->mIsDefault,
-                  aPS->mIsStickyDefault);
-  return true;
-}
-
 // Initialize a PrefParseState instance.
 //
 // |aPS| is the PrefParseState instance.
 // |aReader| is the PrefReader callback function, which will be called once for
 // each preference name value pair extracted.
 // |aReporter| is the PrefParseErrorReporter callback function, which will be
 // called if we encounter any errors (stop) or warnings (continue) during
 // parsing.
@@ -1981,19 +1938,50 @@ PREF_ParseBuf(PrefParseState* aPS, const
           return false;
         }
         break;
 
       // function terminator ';' parsing
       case PREF_PARSE_UNTIL_SEMICOLON:
         // tolerate only whitespace and embedded comments
         if (c == ';') {
-          if (!pref_DoCallback(aPS)) {
-            return false;
+
+          PrefValue value;
+
+          switch (aPS->mVtype) {
+            case PrefType::String:
+              value.mStringVal = aPS->mVb;
+              break;
+
+            case PrefType::Int:
+              if ((aPS->mVb[0] == '-' || aPS->mVb[0] == '+') &&
+                  aPS->mVb[1] == '\0') {
+                pref_ReportParseProblem(*aPS, "invalid integer value", 0, true);
+                NS_WARNING("malformed integer value");
+                return false;
+              }
+              value.mIntVal = atoi(aPS->mVb);
+              break;
+
+            case PrefType::Bool:
+              value.mBoolVal = (aPS->mVb == kTrue);
+              break;
+
+            default:
+              break;
           }
+
+          // We've extracted a complete name/value pair.
+          aPS->mReader(aPS->mClosure,
+                       aPS->mLb,
+                       value,
+                       aPS->mVtype,
+                       aPS->mIsDefault,
+                       aPS->mIsStickyDefault);
+
           state = PREF_PARSE_INIT;
         } else if (c == '/') {
           aPS->mNextState = state; // return here when done with comment
           state = PREF_PARSE_COMMENT_MAYBE_START;
         } else if (!isspace(c)) {
           pref_ReportParseProblem(
             *aPS, "need space, comment or semicolon", lineNum, true);
           NS_WARNING("malformed pref file");