Bug 889219. Part 3: Clean up string usage for printing date/time headers. r=mats
authorRobert O'Callahan <robert@ocallahan.org>
Wed, 24 Jul 2013 23:48:54 +1200
changeset 152107 c7af5345cafc9915c7f9e1638b79996b0eae7786
parent 152106 a005d2b576e4b0789b7a51f9741eb75495cc8cff
child 152108 a745c57499ffed6c8037fdc4d69721ea61d8acc4
push id2859
push userakeybl@mozilla.com
push dateMon, 16 Sep 2013 19:14:59 +0000
treeherdermozilla-beta@87d3c51cd2bf [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmats
bugs889219
milestone25.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 889219. Part 3: Clean up string usage for printing date/time headers. r=mats
layout/generic/nsPageFrame.cpp
layout/generic/nsSimplePageSequence.cpp
layout/generic/nsSimplePageSequence.h
--- a/layout/generic/nsPageFrame.cpp
+++ b/layout/generic/nsPageFrame.cpp
@@ -186,21 +186,17 @@ nsPageFrame::ProcessSpecialCodes(const n
 {
 
   aNewStr = aStr;
 
   // Search to see if the &D code is in the string 
   // then subst in the current date/time
   NS_NAMED_LITERAL_STRING(kDate, "&D");
   if (aStr.Find(kDate) != kNotFound) {
-    if (mPD->mDateTimeStr != nullptr) {
-      aNewStr.ReplaceSubstring(kDate.get(), mPD->mDateTimeStr);
-    } else {
-      aNewStr.ReplaceSubstring(kDate.get(), EmptyString().get());
-    }
+    aNewStr.ReplaceSubstring(kDate.get(), mPD->mDateTimeStr.get());
   }
 
   // NOTE: Must search for &PT before searching for &P
   //
   // Search to see if the "page number and page" total code are in the string
   // and replace the page number and page total code with the actual
   // values
   NS_NAMED_LITERAL_STRING(kPageAndTotal, "&PT");
--- a/layout/generic/nsSimplePageSequence.cpp
+++ b/layout/generic/nsSimplePageSequence.cpp
@@ -54,29 +54,24 @@ GetLayoutPrintingLog()
 #define PR_PL(_p1)  PR_LOG(GetLayoutPrintingLog(), PR_LOG_DEBUG, _p1)
 #else
 #define PR_PL(_p1)
 #endif
 
 // This object a shared by all the nsPageFrames 
 // parented to a SimplePageSequenceFrame
 nsSharedPageData::nsSharedPageData() :
-  mDateTimeStr(nullptr),
   mHeadFootFont(nullptr),
-  mReflowSize(0,0),
-  mReflowMargin(0,0,0,0),
-  mEdgePaperMargin(0,0,0,0),
   mPageContentXMost(0),
   mPageContentSize(0)
 {
 }
 
 nsSharedPageData::~nsSharedPageData()
 {
-  nsMemory::Free(mDateTimeStr);
   delete mHeadFootFont;
 }
 
 nsIFrame*
 NS_NewSimplePageSequenceFrame(nsIPresShell* aPresShell, nsStyleContext* aContext)
 {
   return new (aPresShell) nsSimplePageSequenceFrame(aContext);
 }
@@ -294,18 +289,17 @@ nsSimplePageSequenceFrame::Reflow(nsPres
   nsAutoString formattedDateString;
   time_t ltime;
   time( &ltime );
   if (NS_SUCCEEDED(mDateFormatter->FormatTime(nullptr /* nsILocale* locale */,
                                               kDateFormatShort,
                                               kTimeFormatNoSeconds,
                                               ltime,
                                               formattedDateString))) {
-    PRUnichar * uStr = ToNewUnicode(formattedDateString);
-    SetDateTimeStr(uStr); // memory will be freed
+    SetDateTimeStr(formattedDateString);
   }
 
   // Return our desired size
   // Adjust the reflow size by PrintPreviewScale so the scrollbars end up the
   // correct size
   SetDesiredSize(aDesiredSize, aReflowState, maxXMost, y);
 
   aDesiredSize.SetOverflowAreasToDesiredBounds();
@@ -835,24 +829,20 @@ nsSimplePageSequenceFrame::SetPageNumber
     mPageData->mPageNumFormat = aFormatStr;
   } else {
     mPageData->mPageNumAndTotalsFormat = aFormatStr;
   }
 }
 
 //------------------------------------------------------------------------------
 void
-nsSimplePageSequenceFrame::SetDateTimeStr(PRUnichar * aDateTimeStr)
+nsSimplePageSequenceFrame::SetDateTimeStr(const nsAString& aDateTimeStr)
 { 
-  NS_ASSERTION(aDateTimeStr != nullptr, "DateTime string cannot be null!");
   NS_ASSERTION(mPageData != nullptr, "mPageData string cannot be null!");
 
-  if (mPageData->mDateTimeStr != nullptr) {
-    nsMemory::Free(mPageData->mDateTimeStr);
-  }
   mPageData->mDateTimeStr = aDateTimeStr;
 }
 
 //------------------------------------------------------------------------------
 // For Shrink To Fit
 //
 // Return the percentage that the page needs to shrink to 
 //
--- a/layout/generic/nsSimplePageSequence.h
+++ b/layout/generic/nsSimplePageSequence.h
@@ -17,17 +17,17 @@
 // This class maintains all the data that 
 // is used by all the page frame
 // It lives while the nsSimplePageSequenceFrame lives
 class nsSharedPageData {
 public:
   nsSharedPageData();
   ~nsSharedPageData();
 
-  PRUnichar * mDateTimeStr;
+  nsString    mDateTimeStr;
   nsFont *    mHeadFootFont;
   nsString    mPageNumFormat;
   nsString    mPageNumAndTotalsFormat;
   nsString    mDocTitle;
   nsString    mDocURL;
 
   nsSize      mReflowSize;
   nsMargin    mReflowMargin;
@@ -103,17 +103,17 @@ public:
 
 protected:
   nsSimplePageSequenceFrame(nsStyleContext* aContext);
   virtual ~nsSimplePageSequenceFrame();
 
   void SetPageNumberFormat(const char* aPropName, const char* aDefPropVal, bool aPageNumOnly);
 
   // SharedPageData Helper methods
-  void SetDateTimeStr(PRUnichar * aDateTimeStr);
+  void SetDateTimeStr(const nsAString& aDateTimeStr);
   void SetPageNumberFormat(const nsAString& aFormatStr, bool aForPageNumOnly);
 
   // Sets the frame desired size to the size of the viewport, or the given
   // nscoords, whichever is larger. Print scaling is applied in this function.
   void SetDesiredSize(nsHTMLReflowMetrics& aDesiredSize,
                       const nsHTMLReflowState& aReflowState,
                       nscoord aWidth, nscoord aHeight);