Bug 1415982 - Port bug 1415980: cope with PLDHashEntryHdr no longer being copyable. f=froydnj, rs=jorgk
authorBen Campbell <benc@thunderbird.net>
Fri, 24 Aug 2018 16:52:04 +1200
changeset 33198 c33ef0679b50abf286fae6f23b6786ff87ae6552
parent 33197 9567ebfd9783fd7b82956e59a18ed58d6f97faff
child 33199 66c355e529f52dd7bb136b387b1f1ceaae5d5591
push id387
push userclokep@gmail.com
push dateMon, 10 Dec 2018 21:30:47 +0000
reviewersjorgk
bugs1415982, 1415980
Bug 1415982 - Port bug 1415980: cope with PLDHashEntryHdr no longer being copyable. f=froydnj, rs=jorgk
mailnews/db/msgdb/src/nsMsgDatabase.cpp
mailnews/extensions/bayesian-spam-filter/src/nsBayesianFilter.cpp
--- a/mailnews/db/msgdb/src/nsMsgDatabase.cpp
+++ b/mailnews/db/msgdb/src/nsMsgDatabase.cpp
@@ -730,20 +730,17 @@ nsMsgDatabase::MatchEntry(const PLDHashE
 {
   const MsgHdrHashElement* hdr = static_cast<const MsgHdrHashElement*>(aEntry);
   return aKey == (const void *)(uintptr_t) hdr->mKey; // ### or get the key from the hdr...
 }
 
 void
 nsMsgDatabase::MoveEntry(PLDHashTable* aTable, const PLDHashEntryHdr* aFrom, PLDHashEntryHdr* aTo)
 {
-  const MsgHdrHashElement* from = static_cast<const MsgHdrHashElement*>(aFrom);
-  MsgHdrHashElement* to = static_cast<MsgHdrHashElement*>(aTo);
-  // ### eh? Why is this needed? I don't think we have a copy operator?
-  *to = *from;
+  new (KnownNotNull, aTo) MsgHdrHashElement(std::move(*((MsgHdrHashElement *)aFrom)));
 }
 
 void
 nsMsgDatabase::ClearEntry(PLDHashTable* aTable, PLDHashEntryHdr* aEntry)
 {
   MsgHdrHashElement* element = static_cast<MsgHdrHashElement*>(aEntry);
   element->mHdr = nullptr; // eh? Need to release this or not?
   element->mKey = nsMsgKey_None; // eh?
--- a/mailnews/extensions/bayesian-spam-filter/src/nsBayesianFilter.cpp
+++ b/mailnews/extensions/bayesian-spam-filter/src/nsBayesianFilter.cpp
@@ -74,16 +74,22 @@ struct BaseToken : public PLDHashEntryHd
 };
 
 // token for a particular message
 // mCount, mAnalysisLink are initialized to zero by the hash code
 struct Token : public BaseToken {
     uint32_t mCount;
     uint32_t mAnalysisLink; // index in mAnalysisStore of the AnalysisPerToken
                             // object for the first trait for this token
+    // Helper to support Tokenizer::copyTokens()
+    void clone(const Token& other) {
+      mWord = other.mWord;
+      mCount = other.mCount;
+      mAnalysisLink = other.mAnalysisLink;
+    }
 };
 
 // token stored in a training file for a group of messages
 // mTraitLink is initialized to 0 by the hash code
 struct CorpusToken : public BaseToken
 {
     uint32_t mTraitLink;    // index in mTraitStore of the TraitPerToken
                             // object for the first trait for this token
@@ -886,28 +892,31 @@ void Tokenizer::UnescapeCString(nsCStrin
     }
   }
   result.SetLength(writeIter - writeStart);
   aCString.Assign(result);
 }
 
 Token* Tokenizer::copyTokens()
 {
-    uint32_t count = countTokens();
-    if (count > 0) {
-        Token* tokens = new Token[count];
-        if (tokens) {
-            Token* tp = tokens;
-            TokenEnumeration e(&mTokenTable);
-            while (e.hasMoreTokens())
-                *tp++ = *(static_cast<Token*>(e.nextToken()));
-        }
-        return tokens;
+  uint32_t count = countTokens();
+  if (count > 0) {
+    Token* tokens = new Token[count];
+    if (tokens) {
+      Token* tp = tokens;
+      TokenEnumeration e(&mTokenTable);
+      while (e.hasMoreTokens()) {
+        Token* src = static_cast<Token*>(e.nextToken());
+        tp->clone(*src);
+        ++tp;
+      }
     }
-    return NULL;
+    return tokens;
+  }
+  return NULL;
 }
 
 class TokenAnalyzer {
 public:
     virtual ~TokenAnalyzer() {}
 
     virtual void analyzeTokens(Tokenizer& tokenizer) = 0;
     void setTokenListener(nsIStreamListener *aTokenListener)