Bug 1305202 - Use NullString() more and remove superfluous Truncates(). r=smaug
authorThomas Wisniewski <wisniewskit@gmail.com>
Fri, 23 Sep 2016 21:10:01 -0400
changeset 358277 db4aece012b78248d23ae3f982c776db924c95f8
parent 358276 a2a3082dd360f7f8d07f30de61a5ac67d13fca2c
child 358278 40417bdcaedecc7f7430bc45ac1b703eb7859d34
push id6795
push userjlund@mozilla.com
push dateMon, 23 Jan 2017 14:19:46 +0000
treeherdermozilla-beta@76101b503191 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerssmaug
bugs1305202
milestone52.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 1305202 - Use NullString() more and remove superfluous Truncates(). r=smaug
dom/ipc/Blob.cpp
dom/json/nsJSON.cpp
dom/plugins/ipc/PluginMessageUtils.h
js/xpconnect/src/XPCConvert.cpp
parser/html/nsHtml5TreeOperation.cpp
storage/Variant.h
storage/mozStorageArgValueArray.cpp
storage/mozStorageStatement.cpp
toolkit/components/places/nsNavBookmarks.cpp
xpcom/ds/nsVariant.cpp
--- a/dom/ipc/Blob.cpp
+++ b/dom/ipc/Blob.cpp
@@ -3569,20 +3569,17 @@ BlobChild::SetMysteryBlobInfo(const nsSt
 
 bool
 BlobChild::SetMysteryBlobInfo(const nsString& aContentType, uint64_t aLength)
 {
   AssertIsOnOwningThread();
   MOZ_ASSERT(mBlobImpl);
   MOZ_ASSERT(mRemoteBlobImpl);
 
-  nsString voidString;
-  voidString.SetIsVoid(true);
-
-  mBlobImpl->SetLazyData(voidString, aContentType, aLength, INT64_MAX);
+  mBlobImpl->SetLazyData(NullString(), aContentType, aLength, INT64_MAX);
 
   NormalBlobConstructorParams params(aContentType,
                                      aLength,
                                      void_t() /* optionalBlobData */);
   return SendResolveMystery(params);
 }
 
 void
@@ -4395,20 +4392,17 @@ BlobParent::RecvResolveMystery(const Res
       const NormalBlobConstructorParams& params =
         aParams.get_NormalBlobConstructorParams();
 
       if (NS_WARN_IF(params.length() == UINT64_MAX)) {
         ASSERT_UNLESS_FUZZING();
         return false;
       }
 
-      nsString voidString;
-      voidString.SetIsVoid(true);
-
-      mBlobImpl->SetLazyData(voidString,
+      mBlobImpl->SetLazyData(NullString(),
                              params.contentType(),
                              params.length(),
                              INT64_MAX);
       return true;
     }
 
     case ResolveMysteryParams::TFileBlobConstructorParams: {
       const FileBlobConstructorParams& params =
--- a/dom/json/nsJSON.cpp
+++ b/dom/json/nsJSON.cpp
@@ -65,30 +65,28 @@ nsJSON::Encode(JS::Handle<JS::Value> aVa
                nsAString &aJSON)
 {
   // This function should only be called from JS.
   nsresult rv = WarnDeprecatedMethod(EncodeWarning);
   if (NS_FAILED(rv))
     return rv;
 
   if (aArgc == 0) {
-    aJSON.Truncate();
     aJSON.SetIsVoid(true);
     return NS_OK;
   }
 
   nsJSONWriter writer;
   rv = EncodeInternal(cx, aValue, &writer);
 
   // FIXME: bug 408838. Get exception types sorted out
   if (NS_SUCCEEDED(rv) || rv == NS_ERROR_INVALID_ARG) {
     rv = NS_OK;
     // if we didn't consume anything, it's not JSON, so return null
     if (!writer.DidWrite()) {
-      aJSON.Truncate();
       aJSON.SetIsVoid(true);
     } else {
       writer.FlushBuffer();
       aJSON.Append(writer.mOutputString);
     }
   }
 
   return rv;
--- a/dom/plugins/ipc/PluginMessageUtils.h
+++ b/dom/plugins/ipc/PluginMessageUtils.h
@@ -248,19 +248,17 @@ inline bool IsDrawingModelDirect(int16_t
 }
 
 // in NPAPI, char* == nullptr is sometimes meaningful.  the following is
 // helper code for dealing with nullable nsCString's
 inline nsCString
 NullableString(const char* aString)
 {
     if (!aString) {
-        nsCString str;
-        str.SetIsVoid(true);
-        return str;
+        return NullCString();
     }
     return nsCString(aString);
 }
 
 inline const char*
 NullableStringGet(const nsCString& str)
 {
   if (str.IsVoid())
--- a/js/xpconnect/src/XPCConvert.cpp
+++ b/js/xpconnect/src/XPCConvert.cpp
@@ -635,17 +635,16 @@ XPCConvert::JSData2Native(void* d, Handl
 
         return true;
     }
 
     case nsXPTType::T_CSTRING:
     {
         if (s.isNull() || s.isUndefined()) {
             nsACString* rs = *((nsACString**)d);
-            rs->Truncate();
             rs->SetIsVoid(true);
             return true;
         }
 
         // The JS val is neither null nor void...
         JSString* str = ToString(cx, s);
         if (!str) {
             return false;
--- a/parser/html/nsHtml5TreeOperation.cpp
+++ b/parser/html/nsHtml5TreeOperation.cpp
@@ -560,24 +560,22 @@ nsresult
 nsHtml5TreeOperation::AppendDoctypeToDocument(nsIAtom* aName,
                                               const nsAString& aPublicId,
                                               const nsAString& aSystemId,
                                               nsHtml5DocumentBuilder* aBuilder)
 {
   // Adapted from nsXMLContentSink
   // Create a new doctype node
   nsCOMPtr<nsIDOMDocumentType> docType;
-  nsAutoString voidString;
-  voidString.SetIsVoid(true);
   NS_NewDOMDocumentType(getter_AddRefs(docType),
                         aBuilder->GetNodeInfoManager(),
                         aName,
                         aPublicId,
                         aSystemId,
-                        voidString);
+                        NullString());
   NS_ASSERTION(docType, "Doctype creation failed.");
   nsCOMPtr<nsIContent> asContent = do_QueryInterface(docType);
   return AppendToDocument(asContent, aBuilder);
 }
 
 nsIContent*
 nsHtml5TreeOperation::GetDocumentFragmentForTemplate(nsIContent* aNode)
 {
--- a/storage/Variant.h
+++ b/storage/Variant.h
@@ -352,25 +352,23 @@ public:
     NS_ENSURE_ARG_POINTER(_type);
     *_type = nsIDataType::VTYPE_EMPTY;
     return NS_OK;
   }
 
   NS_IMETHOD GetAsAUTF8String(nsACString &_str)
   {
     // Return a void string.
-    _str.Truncate(0);
     _str.SetIsVoid(true);
     return NS_OK;
   }
 
   NS_IMETHOD GetAsAString(nsAString &_str)
   {
     // Return a void string.
-    _str.Truncate(0);
     _str.SetIsVoid(true);
     return NS_OK;
   }
 };
 
 ////////////////////////////////////////////////////////////////////////////////
 //// Template Implementation
 
--- a/storage/mozStorageArgValueArray.cpp
+++ b/storage/mozStorageArgValueArray.cpp
@@ -103,17 +103,16 @@ NS_IMETHODIMP
 ArgValueArray::GetUTF8String(uint32_t aIndex,
                              nsACString &_value)
 {
   ENSURE_INDEX_VALUE(aIndex, mArgc);
 
   if (::sqlite3_value_type(mArgv[aIndex]) == SQLITE_NULL) {
     // NULL columns should have IsVoid set to distinguish them from an empty
     // string.
-    _value.Truncate(0);
     _value.SetIsVoid(true);
   }
   else {
     _value.Assign(reinterpret_cast<const char *>(::sqlite3_value_text(mArgv[aIndex])),
                   ::sqlite3_value_bytes(mArgv[aIndex]));
   }
   return NS_OK;
 }
@@ -122,17 +121,16 @@ NS_IMETHODIMP
 ArgValueArray::GetString(uint32_t aIndex,
                          nsAString &_value)
 {
   ENSURE_INDEX_VALUE(aIndex, mArgc);
 
   if (::sqlite3_value_type(mArgv[aIndex]) == SQLITE_NULL) {
     // NULL columns should have IsVoid set to distinguish them from an empty
     // string.
-    _value.Truncate(0);
     _value.SetIsVoid(true);
   } else {
     _value.Assign(static_cast<const char16_t *>(::sqlite3_value_text16(mArgv[aIndex])),
                   ::sqlite3_value_bytes16(mArgv[aIndex]) / 2);
   }
   return NS_OK;
 }
 
--- a/storage/mozStorageStatement.cpp
+++ b/storage/mozStorageStatement.cpp
@@ -767,17 +767,16 @@ Statement::GetUTF8String(uint32_t aIndex
 {
   // Get type of Index will check aIndex for us, so we don't have to.
   int32_t type;
   nsresult rv = GetTypeOfIndex(aIndex, &type);
   NS_ENSURE_SUCCESS(rv, rv);
   if (type == mozIStorageStatement::VALUE_TYPE_NULL) {
     // NULL columns should have IsVoid set to distinguish them from the empty
     // string.
-    _value.Truncate(0);
     _value.SetIsVoid(true);
   }
   else {
     const char *value =
       reinterpret_cast<const char *>(::sqlite3_column_text(mDBStatement,
                                                            aIndex));
     _value.Assign(value, ::sqlite3_column_bytes(mDBStatement, aIndex));
   }
@@ -790,17 +789,16 @@ Statement::GetString(uint32_t aIndex,
 {
   // Get type of Index will check aIndex for us, so we don't have to.
   int32_t type;
   nsresult rv = GetTypeOfIndex(aIndex, &type);
   NS_ENSURE_SUCCESS(rv, rv);
   if (type == mozIStorageStatement::VALUE_TYPE_NULL) {
     // NULL columns should have IsVoid set to distinguish them from the empty
     // string.
-    _value.Truncate(0);
     _value.SetIsVoid(true);
   } else {
     const char16_t *value =
       static_cast<const char16_t *>(::sqlite3_column_text16(mDBStatement,
                                                              aIndex));
     _value.Assign(value, ::sqlite3_column_bytes16(mDBStatement, aIndex) / 2);
   }
   return NS_OK;
--- a/toolkit/components/places/nsNavBookmarks.cpp
+++ b/toolkit/components/places/nsNavBookmarks.cpp
@@ -794,32 +794,30 @@ nsNavBookmarks::InsertSeparator(int64_t 
     index = aIndex;
     // Create space for the insertion.
     rv = AdjustIndices(aParent, index, INT32_MAX, 1);
     NS_ENSURE_SUCCESS(rv, rv);
   }
 
   *aNewItemId = -1;
   // Set a NULL title rather than an empty string.
-  nsCString voidString;
-  voidString.SetIsVoid(true);
   nsAutoCString guid(aGUID);
   PRTime dateAdded = RoundedPRNow();
-  rv = InsertBookmarkInDB(-1, SEPARATOR, aParent, index, voidString, dateAdded,
+  rv = InsertBookmarkInDB(-1, SEPARATOR, aParent, index, NullCString(), dateAdded,
                           0, folderGuid, grandParentId, nullptr, aSource,
                           aNewItemId, guid);
   NS_ENSURE_SUCCESS(rv, rv);
 
   rv = transaction.Commit();
   NS_ENSURE_SUCCESS(rv, rv);
 
   NOTIFY_OBSERVERS(mCanNotify, mCacheObservers, mObservers,
                    nsINavBookmarkObserver,
                    OnItemAdded(*aNewItemId, aParent, index, TYPE_SEPARATOR,
-                               nullptr, voidString, dateAdded, guid, folderGuid,
+                               nullptr, NullCString(), dateAdded, guid, folderGuid,
                                aSource));
 
   return NS_OK;
 }
 
 
 nsresult
 nsNavBookmarks::GetLastChildId(int64_t aFolderId, int64_t* aItemId)
--- a/xpcom/ds/nsVariant.cpp
+++ b/xpcom/ds/nsVariant.cpp
@@ -761,17 +761,16 @@ nsDiscriminatedUnion::ToString(nsACStrin
     case nsIDataType::VTYPE_WCHAR:
       NS_ERROR("ToString being called for a string type - screwy logic!");
       MOZ_FALLTHROUGH;
 
     // XXX We might want stringified versions of these... ???
 
     case nsIDataType::VTYPE_VOID:
     case nsIDataType::VTYPE_EMPTY:
-      aOutString.Truncate();
       aOutString.SetIsVoid(true);
       return NS_OK;
 
     case nsIDataType::VTYPE_EMPTY_ARRAY:
     case nsIDataType::VTYPE_ARRAY:
     case nsIDataType::VTYPE_INTERFACE:
     case nsIDataType::VTYPE_INTERFACE_IS:
     default: