Bug 1359707 - Preferences::GetBool(PREF_ALWAYS_INCLUDE_RUBY) should use AddBoolVarCache. r?smaug draft
authorMakoto Kato <m_kato@ga2.so-net.ne.jp>
Thu, 27 Apr 2017 12:44:24 +0900 (2017-04-27)
changeset 569390 d44bc48249fe225f9e88ec31a2e69e1e350a031e
parent 569138 0b77ed3f26c5335503bc16e85b8c067382e7bb1e
child 626196 d075b8f542f4f6315ca7cbf0defc483673b41a41
push id56162
push userm_kato@ga2.so-net.ne.jp
push dateThu, 27 Apr 2017 11:14:25 +0000 (2017-04-27)
reviewerssmaug
bugs1359707
milestone55.0a1
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;
 }