Bug 1487051 - Remove EnsureStringLength(). r=froydnj
authorHenri Sivonen <hsivonen@hsivonen.fi>
Tue, 04 Sep 2018 18:25:11 +0000
changeset 483027 887812e501fcae905970ebf8b4ad4ac7a65bc6f3
parent 483026 af2c47f0c8d725b2e50a1e43ed3581815a8b66fa
child 483028 a72616d7328085de4bd39a02861bfcc969b21232
push id232
push userfmarier@mozilla.com
push dateWed, 05 Sep 2018 20:45:54 +0000
reviewersfroydnj
bugs1487051
milestone63.0a1
Bug 1487051 - Remove EnsureStringLength(). r=froydnj MozReview-Commit-ID: 4X4Rrs8xHTF Differential Revision: https://phabricator.services.mozilla.com/D4930
widget/cocoa/TextInputHandler.mm
xpcom/string/nsReadableUtils.h
--- a/widget/cocoa/TextInputHandler.mm
+++ b/widget/cocoa/TextInputHandler.mm
@@ -376,17 +376,19 @@ TISInputSourceWrapper::TranslateToString
   MOZ_LOG(gLog, LogLevel::Info,
     ("%p TISInputSourceWrapper::TranslateToString, err=0x%X, len=%zu",
      this, static_cast<int>(err), len));
 
   NS_ENSURE_TRUE(err == noErr, false);
   if (len == 0) {
     return true;
   }
-  NS_ENSURE_TRUE(EnsureStringLength(aStr, len), false);
+  if (!aStr.SetLength(len, fallible)) {
+    return false;
+  }
   NS_ASSERTION(sizeof(char16_t) == sizeof(UniChar),
                "size of char16_t and size of UniChar are different");
   memcpy(aStr.BeginWriting(), chars, len * sizeof(char16_t));
 
   MOZ_LOG(gLog, LogLevel::Info,
     ("%p TISInputSourceWrapper::TranslateToString, aStr=\"%s\"",
      this, NS_ConvertUTF16toUTF8(aStr).get()));
 
--- a/xpcom/string/nsReadableUtils.h
+++ b/xpcom/string/nsReadableUtils.h
@@ -812,17 +812,9 @@ const nsCString& VoidCString();
  */
 int32_t
 CompareUTF8toUTF16(const nsACString& aUTF8String,
                    const nsAString& aUTF16String,
                    bool* aErr = nullptr);
 
 void AppendUCS4ToUTF16(const uint32_t aSource, nsAString& aDest);
 
-template<class T>
-inline bool
-EnsureStringLength(T& aStr, uint32_t aLen)
-{
-  aStr.SetLength(aLen);
-  return (aStr.Length() == aLen);
-}
-
 #endif // !defined(nsReadableUtils_h___)