Bug 826541 Suboptimal string copying in nsAttrValue::ToString r=bz
authorNeil Rashbrook <neil@parkwaycc.co.uk>
Fri, 04 Jan 2013 20:31:50 +0000
changeset 117668 587a0a974cf8bb874054a095c92d66639fe56d3d
parent 117667 4b2611eed98a57feaec76e81bbfbd4081fd7c173
child 117669 ac810061a17517f1ffdad2e07fc0b9ef9f98a1c5
push id24110
push userphilringnalda@gmail.com
push dateSat, 05 Jan 2013 23:57:49 +0000
treeherdermozilla-central@20d1a5916ef6 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbz
bugs826541
milestone20.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 826541 Suboptimal string copying in nsAttrValue::ToString r=bz
content/base/src/nsAttrValue.cpp
content/base/src/nsAttrValueInlines.h
--- a/content/base/src/nsAttrValue.cpp
+++ b/content/base/src/nsAttrValue.cpp
@@ -25,43 +25,42 @@
 #include "nsStyledElement.h"
 
 using namespace mozilla;
 
 #define MISC_STR_PTR(_cont) \
   reinterpret_cast<void*>((_cont)->mStringBits & NS_ATTRVALUE_POINTERVALUE_MASK)
 
 bool
-MiscContainer::GetString(nsDependentString& aString) const
+MiscContainer::GetString(nsAString& aString) const
 {
   void* ptr = MISC_STR_PTR(this);
 
   if (!ptr) {
     return false;
   }
 
   if (static_cast<nsAttrValue::ValueBaseType>(mStringBits &
                                               NS_ATTRVALUE_BASETYPE_MASK) ==
       nsAttrValue::eStringBase) {
     nsStringBuffer* buffer = static_cast<nsStringBuffer*>(ptr);
     if (!buffer) {
       return false;
     }
 
-    aString.Rebind(reinterpret_cast<PRUnichar*>(buffer->Data()),
-                   buffer->StorageSize() / sizeof(PRUnichar) - 1);
+    buffer->ToString(buffer->StorageSize() / sizeof(PRUnichar) - 1, aString);
     return true;
   }
 
   nsIAtom* atom = static_cast<nsIAtom*>(ptr);
   if (!atom) {
     return false;
   }
 
-  aString.Rebind(atom->GetUTF16String(), atom->GetLength());
+  atom->ToString(aString);
   return true;
 }
 
 void
 MiscContainer::Cache()
 {
   // Not implemented for anything else yet.
   MOZ_ASSERT(mType == nsAttrValue::eCSSStyleRule);
@@ -70,17 +69,17 @@ MiscContainer::Cache()
   MOZ_ASSERT(!mValue.mCached);
 
   css::StyleRule* rule = mValue.mCSSStyleRule;
   nsHTMLCSSStyleSheet* sheet = rule->GetHTMLCSSStyleSheet();
   if (!sheet) {
     return;
   }
 
-  nsDependentString str;
+  nsString str;
   bool gotString = GetString(str);
   if (!gotString) {
     return;
   }
 
   sheet->CacheStyleAttr(str, this);
   mValue.mCached = 1;
 
@@ -102,17 +101,17 @@ MiscContainer::Evict()
   if (!mValue.mCached) {
     return;
   }
 
   css::StyleRule* rule = mValue.mCSSStyleRule;
   nsHTMLCSSStyleSheet* sheet = rule->GetHTMLCSSStyleSheet();
   MOZ_ASSERT(sheet);
 
-  nsDependentString str;
+  nsString str;
   DebugOnly<bool> gotString = GetString(str);
   MOZ_ASSERT(gotString);
 
   sheet->EvictStyleAttr(str, this);
   mValue.mCached = 0;
 }
 
 nsTArray<const nsAttrValue::EnumTable*>* nsAttrValue::sEnumTableArray = nullptr;
@@ -573,19 +572,17 @@ nsAttrValue::SwapValueWith(nsAttrValue& 
 
 void
 nsAttrValue::ToString(nsAString& aResult) const
 {
   MiscContainer* cont = nullptr;
   if (BaseType() == eOtherBase) {
     cont = GetMiscContainer();
 
-    nsDependentString str;
-    if (cont->GetString(str)) {
-      aResult = str;
+    if (cont->GetString(aResult)) {
       return;
     }
   }
 
   switch(Type()) {
     case eString:
     {
       nsStringBuffer* str = static_cast<nsStringBuffer*>(GetPtr());
--- a/content/base/src/nsAttrValueInlines.h
+++ b/content/base/src/nsAttrValueInlines.h
@@ -62,17 +62,17 @@ struct MiscContainer
   {
     if (IsRefCounted()) {
       MOZ_ASSERT(mValue.mRefCount == 0);
       MOZ_ASSERT(!mValue.mCached);
     }
     MOZ_COUNT_DTOR(MiscContainer);
   }
 
-  bool GetString(nsDependentString& aString) const;
+  bool GetString(nsAString& aString) const;
 
   inline bool IsRefCounted() const
   {
     // Nothing stops us from refcounting (and sharing) other types of
     // MiscContainer (except eDoubleValue types) but there's no compelling
     // reason to 
     return mType == nsAttrValue::eCSSStyleRule;
   }