Bug 1552752: Part 2) Rename `ConvertAndWrite` to `EncodeAndWrite` and slighlty simplify method. r=hsivonen
authorMirko Brodesser <mbrodesser@mozilla.com>
Tue, 21 May 2019 07:36:49 +0000
changeset 474676 0e382475292d9801921403db032eb0e9dba31c12
parent 474675 d94707ff797ed94e04ab286a6d9e43a4e7e6480e
child 474677 a57a160207c492159c70a7bf4d41b710cbac7eaa
push id36044
push userrmaries@mozilla.com
push dateTue, 21 May 2019 15:45:34 +0000
treeherdermozilla-central@78571bb1f20e [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewershsivonen
bugs1552752
milestone69.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 1552752: Part 2) Rename `ConvertAndWrite` to `EncodeAndWrite` and slighlty simplify method. r=hsivonen Differential Revision: https://phabricator.services.mozilla.com/D31768
dom/base/nsDocumentEncoder.cpp
--- a/dom/base/nsDocumentEncoder.cpp
+++ b/dom/base/nsDocumentEncoder.cpp
@@ -70,19 +70,21 @@ class TextStreamer {
   /**
    * @param aString Will be truncated.
    */
   nsresult ForceFlush(nsAString& aString);
 
  private:
   const static uint32_t kMaxLengthBeforeFlush = 1024;
 
-  nsresult ConvertAndWrite(const nsAString& aString);
+  const static uint32_t kEncoderBufferSizeInBytes = 4096;
 
-  nsresult ConvertAndWriteAndTruncate(nsAString& aString);
+  nsresult EncodeAndWrite(const nsAString& aString);
+
+  nsresult EncodeAndWriteAndTruncate(nsAString& aString);
 
   const nsCOMPtr<nsIOutputStream> mStream;
   const UniquePtr<Encoder> mUnicodeEncoder;
   const bool mIsPlainText;
 };
 
 TextStreamer::TextStreamer(nsIOutputStream& aStream,
                            UniquePtr<Encoder> aUnicodeEncoder,
@@ -92,33 +94,32 @@ TextStreamer::TextStreamer(nsIOutputStre
       mIsPlainText(aIsPlainText) {
   MOZ_ASSERT(mUnicodeEncoder);
 }
 
 nsresult TextStreamer::FlushIfStringLongEnough(nsAString& aString) {
   nsresult rv = NS_OK;
 
   if (aString.Length() > kMaxLengthBeforeFlush) {
-    rv = ConvertAndWriteAndTruncate(aString);
+    rv = EncodeAndWriteAndTruncate(aString);
   }
 
   return rv;
 }
 
 nsresult TextStreamer::ForceFlush(nsAString& aString) {
-  return ConvertAndWriteAndTruncate(aString);
+  return EncodeAndWriteAndTruncate(aString);
 }
 
-nsresult TextStreamer::ConvertAndWrite(const nsAString& aString) {
-  if (!aString.Length()) {
+nsresult TextStreamer::EncodeAndWrite(const nsAString& aString) {
+  if (aString.IsEmpty()) {
     return NS_OK;
   }
 
-  // TODO(mbrodesser): add constant.
-  uint8_t buffer[4096];
+  uint8_t buffer[kEncoderBufferSizeInBytes];
   auto src = MakeSpan(aString);
   auto bufferSpan = MakeSpan(buffer);
   // Reserve space for terminator
   auto dst = bufferSpan.To(bufferSpan.Length() - 1);
   for (;;) {
     uint32_t result;
     size_t read;
     size_t written;
@@ -149,18 +150,18 @@ nsresult TextStreamer::ConvertAndWrite(c
       return rv;
     }
     if (result == kInputEmpty) {
       return NS_OK;
     }
   }
 }
 
-nsresult TextStreamer::ConvertAndWriteAndTruncate(nsAString& aString) {
-  const nsresult rv = ConvertAndWrite(aString);
+nsresult TextStreamer::EncodeAndWriteAndTruncate(nsAString& aString) {
+  const nsresult rv = EncodeAndWrite(aString);
   aString.Truncate();
   return rv;
 }
 
 class nsDocumentEncoder : public nsIDocumentEncoder {
  public:
   nsDocumentEncoder();