Bug 1359707 - Preferences::GetBool(PREF_ALWAYS_INCLUDE_RUBY) should use AddBoolVarCache. r=smaug
authorMakoto Kato <m_kato@ga2.so-net.ne.jp>
Thu, 27 Apr 2017 12:44:24 +0900
changeset 405917 dce18d4780877bd26df8052384ff5dc9e557964d
parent 405916 b780829d73ae41086010a11e8a4a03b8a97575be
child 405918 2e7660e83f7d2b6ad59213fa038cc55873034e1a
push id1490
push usermtabara@mozilla.com
push dateMon, 31 Jul 2017 14:08:16 +0000
treeherdermozilla-release@70e32e6bf15e [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerssmaug
bugs1359707
milestone55.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 1359707 - Preferences::GetBool(PREF_ALWAYS_INCLUDE_RUBY) should use AddBoolVarCache. r=smaug When profiling nsDocumentEncoder::EncodeToStringWithMaxLength for text/plain, 25% is Preferences::GetBool into nsPlainTextSerializer::Init. So we should use AddBoolVarCache for it. MozReview-Commit-ID: 9CVd4OZzzr5
dom/base/nsPlainTextSerializer.cpp
--- a/dom/base/nsPlainTextSerializer.cpp
+++ b/dom/base/nsPlainTextSerializer.cpp
@@ -50,16 +50,19 @@ static const  char16_t kSPACE = ' ';
 static int32_t HeaderLevel(nsIAtom* aTag);
 static int32_t GetUnicharWidth(char16_t ucs);
 static int32_t GetUnicharStringWidth(const char16_t* pwcs, int32_t n);
 
 // Someday may want to make this non-const:
 static const uint32_t TagStackSize = 500;
 static const uint32_t OLStackSize = 100;
 
+static bool gPreferenceInitialized = false;
+static bool gAlwaysIncludeRuby = false;
+
 NS_IMPL_CYCLE_COLLECTING_ADDREF(nsPlainTextSerializer)
 NS_IMPL_CYCLE_COLLECTING_RELEASE(nsPlainTextSerializer)
 
 NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(nsPlainTextSerializer)
   NS_INTERFACE_MAP_ENTRY(nsIContentSerializer)
   NS_INTERFACE_MAP_ENTRY(nsISupports)
 NS_INTERFACE_MAP_END
 
@@ -113,16 +116,22 @@ nsPlainTextSerializer::nsPlainTextSerial
 
   // initialize the OL stack, where numbers for ordered lists are kept
   mOLStack = new int32_t[OLStackSize];
   mOLStackIndex = 0;
 
   mULCount = 0;
 
   mIgnoredChildNodeLevel = 0;
+
+  if (!gPreferenceInitialized) {
+    Preferences::AddBoolVarCache(&gAlwaysIncludeRuby, PREF_ALWAYS_INCLUDE_RUBY,
+                                 true);
+    gPreferenceInitialized = true;
+  }
 }
 
 nsPlainTextSerializer::~nsPlainTextSerializer()
 {
   delete[] mTagStack;
   delete[] mOLStack;
   NS_WARNING_ASSERTION(mHeadLevel == 0, "Wrong head level!");
 }
@@ -185,17 +194,17 @@ nsPlainTextSerializer::Init(uint32_t aFl
     mHeaderStrategy =
       Preferences::GetInt(PREF_HEADER_STRATEGY, mHeaderStrategy);
   }
 
   // The pref is default inited to false in libpref, but we use true
   // as fallback value because we don't want to affect behavior in
   // other places which use this serializer currently.
   mWithRubyAnnotation =
-    Preferences::GetBool(PREF_ALWAYS_INCLUDE_RUBY, true) ||
+    gAlwaysIncludeRuby ||
     (mFlags & nsIDocumentEncoder::OutputRubyAnnotation);
 
   // XXX We should let the caller decide whether to do this or not
   mFlags &= ~nsIDocumentEncoder::OutputNoFramesContent;
 
   return NS_OK;
 }