Bug 1258904 - Part 3: Factor out ToLocalizedStringForKey. r=birtles
authorHiroyuki Ikezoe <hiikezoe@mozilla-japan.org>
Sat, 07 May 2016 17:37:57 +0900
changeset 335537 156b9e7e21c772d011d2c502961ebe4a52b8e026
parent 335536 05cb31c61bf21174e515f31446630225dfe7a60a
child 335538 f4f185cfc034ab987e09650a37aaa19891c7c29d
push id6249
push userjlund@mozilla.com
push dateMon, 01 Aug 2016 13:59:36 +0000
treeherdermozilla-beta@bad9d4f5bf7e [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbirtles
bugs1258904
milestone49.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1258904 - Part 3: Factor out ToLocalizedStringForKey. r=birtles This function will be used for the warning of small content as well. MozReview-Commit-ID: EiUF9CgWGDA
dom/animation/AnimationPerformanceWarning.cpp
dom/animation/AnimationPerformanceWarning.h
--- a/dom/animation/AnimationPerformanceWarning.cpp
+++ b/dom/animation/AnimationPerformanceWarning.cpp
@@ -5,49 +5,46 @@
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #include "AnimationPerformanceWarning.h"
 
 #include "nsContentUtils.h"
 
 namespace mozilla {
 
+template<uint32_t N> nsresult
+AnimationPerformanceWarning::ToLocalizedStringWithIntParams(
+  const char* aKey, nsXPIDLString& aLocalizedString) const
+{
+  nsAutoString strings[N];
+  const char16_t* charParams[N];
+
+  for (size_t i = 0, n = mParams->Length(); i < n; i++) {
+    strings[i].AppendInt((*mParams)[i]);
+    charParams[i] = strings[i].get();
+  }
+
+  return nsContentUtils::FormatLocalizedString(
+      nsContentUtils::eLAYOUT_PROPERTIES, aKey, charParams, aLocalizedString);
+}
+
 bool
 AnimationPerformanceWarning::ToLocalizedString(
   nsXPIDLString& aLocalizedString) const
 {
   const char* key = nullptr;
 
   switch (mType) {
     case Type::ContentTooLarge:
-    {
       MOZ_ASSERT(mParams && mParams->Length() == 7,
                  "Parameter's length should be 7 for ContentTooLarge");
 
-      MOZ_ASSERT(mParams->Length() <= kMaxParamsForLocalization,
-                 "Parameter's length should be less than "
-                 "kMaxParamsForLocalization");
-      // We can pass an array of parameters whose length is greater than 7 to
-      // nsContentUtils::FormatLocalizedString because
-      // nsTextFormatter drops those extra parameters in the end.
-      nsAutoString strings[kMaxParamsForLocalization];
-      const char16_t* charParams[kMaxParamsForLocalization];
-
-      for (size_t i = 0, n = mParams->Length(); i < n; i++) {
-        strings[i].AppendInt((*mParams)[i]);
-        charParams[i] = strings[i].get();
-      }
-
-      nsresult rv = nsContentUtils::FormatLocalizedString(
-        nsContentUtils::eLAYOUT_PROPERTIES,
-        "AnimationWarningContentTooLarge",
-        charParams,
-        aLocalizedString);
-      return NS_SUCCEEDED(rv);
-    }
+      return NS_SUCCEEDED(
+        ToLocalizedStringWithIntParams<7>("AnimationWarningContentTooLarge",
+                                          aLocalizedString));
     case Type::TransformBackfaceVisibilityHidden:
       key = "AnimationWarningTransformBackfaceVisibilityHidden";
       break;
     case Type::TransformPreserve3D:
       key = "AnimationWarningTransformPreserve3D";
       break;
     case Type::TransformSVG:
       key = "AnimationWarningTransformSVG";
--- a/dom/animation/AnimationPerformanceWarning.h
+++ b/dom/animation/AnimationPerformanceWarning.h
@@ -52,16 +52,19 @@ struct AnimationPerformanceWarning
 
   // Indicates why this property could not be animated on the compositor.
   Type mType;
 
   // Optional parameters that may be used for localization.
   Maybe<nsTArray<int32_t>> mParams;
 
   bool ToLocalizedString(nsXPIDLString& aLocalizedString) const;
+  template<uint32_t N>
+  nsresult ToLocalizedStringWithIntParams(
+    const char* aKey, nsXPIDLString& aLocalizedString) const;
 
   bool operator==(const AnimationPerformanceWarning& aOther) const
   {
     return mType == aOther.mType &&
            mParams == aOther.mParams;
   }
   bool operator!=(const AnimationPerformanceWarning& aOther) const
   {