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
--- 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;
}