Closed Bug 258018 Opened 21 years ago Closed 18 years ago

replace nsUInt32Array with nsTArray<PRUint32>

Categories

(MailNews Core :: Backend, defect)

defect
Not set
minor

Tracking

(Not tracked)

RESOLVED FIXED
Future

People

(Reporter: csthomas, Assigned: neil)

References

Details

(Whiteboard: helpwanted)

Attachments

(7 files, 3 obsolete files)

Whiteboard: waiting on 250811
Product: MailNews → Core
Whiteboard: waiting on 250811 → helpwanted , waiting on 250811
Assignee: cst → sspitzer
Target Milestone: --- → Future
Whiteboard: helpwanted , waiting on 250811 → helpwanted
I'm taking a look at working around this code in Correo, and I figured I would fix this while I'm at it. Instead of using |nsValueArray|, my proposal is to use |nsTArray| instead. Taking...
Assignee: sspitzer → nick.kreeger
I don't know if you can completely replace nsUint32Array, but you might base it on nsTArray - we rely on things like sorting and searching a sorted nsUint32Array, especially in nsMsgKeyArray.
(In reply to comment #1) >Instead of using |nsValueArray|, my proposal is to use |nsTArray| instead. Yeah, nsValueArray is going away...
Summary: replace nsUInt32Array with nsValueArray → replace nsUInt32Array with nsTArray<PRUint32>
Attachment #295088 - Flags: superreview?(bienvenu)
Attachment #295088 - Flags: review?(bienvenu)
Attachment #295089 - Flags: superreview?(bienvenu)
Attachment #295089 - Flags: review?(bienvenu)
Comment on attachment 295088 [details] [diff] [review] nsAddrBookSession patch thx for the patch, Neil.
Attachment #295088 - Flags: superreview?(bienvenu)
Attachment #295088 - Flags: superreview+
Attachment #295088 - Flags: review?(bienvenu)
Attachment #295088 - Flags: review+
Attachment #295089 - Flags: superreview?(bienvenu)
Attachment #295089 - Flags: superreview+
Attachment #295089 - Flags: review?(bienvenu)
Attachment #295089 - Flags: review+
Attachment #295109 - Flags: superreview?(bienvenu)
Attachment #295109 - Flags: review?(bienvenu)
Attachment #295110 - Flags: superreview?(bienvenu)
Attachment #295110 - Flags: review?(bienvenu)
Attachment #295109 - Flags: superreview?(bienvenu)
Attachment #295109 - Flags: superreview+
Attachment #295109 - Flags: review?(bienvenu)
Attachment #295109 - Flags: review+
Attachment #295110 - Flags: superreview?(bienvenu)
Attachment #295110 - Flags: superreview+
Attachment #295110 - Flags: review?(bienvenu)
Attachment #295110 - Flags: review+
Attached patch MapiMessage patch (obsolete) — Splinter Review
Attachment #295151 - Flags: superreview?(neil)
Attachment #295151 - Flags: review?(neil)
Comment on attachment 295151 [details] [diff] [review] MapiMessage patch >+ DWORD aNum = m_attachNums[idx]; Might as well make it an nsTArray<DWORD> then - see bug 410479 ;-) Given that bug, I don't think I can fairly review this.
Attachment #295151 - Flags: superreview?(neil)
Attachment #295151 - Flags: review?(neil)
Attached patch GetSelectedIndices patch (obsolete) — Splinter Review
I had to make a bunch of pointers const because Elements() is. I should probably reformat all the affected lines while I'm there... I removed the sorting because tree selections are already sorted.
Attachment #295678 - Flags: superreview?(bienvenu)
Attachment #295678 - Flags: review?(dwitte)
Attachment #295151 - Attachment is obsolete: true
Comment on attachment 295678 [details] [diff] [review] GetSelectedIndices patch >Index: nsMsgDBView.cpp >=================================================================== >@@ -1098,13 +1098,13 @@ >-nsresult nsMsgDBView::GetSelectedIndices(nsUInt32Array *selection) >+nsresult nsMsgDBView::GetSelectedIndices(nsMsgViewIndexArray& selection) > { > if (mTreeSelection) > { > PRInt32 count; > mTreeSelection->GetCount(&count); >- selection->SetSize(count); >+ selection.SetLength(count); > count = 0; > PRInt32 selectionCount; > nsresult rv = mTreeSelection->GetRangeCount(&selectionCount); >@@ -1118,7 +1118,7 @@ > if (startRange >= 0 && startRange < viewSize) > { > for (PRInt32 rangeIndex = startRange; rangeIndex <= endRange && rangeIndex < viewSize; rangeIndex++) >- selection->SetAt(count++, rangeIndex); >+ selection[count++] = rangeIndex; doing a SetLength() call followed by assigning all the elements is efficient, but SetLength() won't zero the data like nsUInt32Array did. so if there's an early return (http://mxr.mozilla.org/mozilla/source/mailnews/base/src/nsMsgDBView.cpp#1116) and your callers don't check the return value of GetSelectedIndices() (they don't) then this is bad, no? SetCapacity() is safer, but i'll go along with SetLength() provided you expand out that NS_ENSURE_SUCCESS to Clear() the array on failure. >@@ -2128,17 +2128,16 @@ >- nsUInt32Array selection; >- GetSelectedIndices(&selection); >- *length = selection.GetSize(); >- PRUint32 numIndicies = *length; >- if (!numIndicies) return NS_OK; >+ nsMsgViewIndexArray selection; >+ GetSelectedIndices(selection); >+ PRUint32 numIndices = selection.Length(); >+ if (!numIndices) return NS_OK; >+ *length = numIndices; want to make the same *length/spelling fixes... >@@ -2151,9 +2150,9 @@ >- nsUInt32Array selection; >- GetSelectedIndices(&selection); >- *length = selection.GetSize(); >+ nsMsgViewIndexArray selection; >+ GetSelectedIndices(selection); >+ *length = selection.Length(); > PRUint32 numIndicies = *length; > if (!numIndicies) return NS_OK; here? r=me with those!
Attachment #295678 - Flags: review?(dwitte) → review+
as a side note, nsAutoTArray inherits from nsTArray, so if you have code like nsAutoTArray<foo, 2> bar; baz(bar); then baz can just have a signature void baz(nsTArray<foo>& aBar); but since you instantiate your array in a bunch of different places the typedef makes sense.
(In reply to comment #12) > >@@ -2128,17 +2128,16 @@ > >- nsUInt32Array selection; > >- GetSelectedIndices(&selection); > >- *length = selection.GetSize(); > >- PRUint32 numIndicies = *length; > >- if (!numIndicies) return NS_OK; > >+ nsMsgViewIndexArray selection; > >+ GetSelectedIndices(selection); > >+ PRUint32 numIndices = selection.Length(); > >+ if (!numIndices) return NS_OK; > >+ *length = numIndices; > > want to make the same *length/spelling fixes... er wait, on second look, is that right? *length won't get set to 0 before returning.
(In reply to comment #14) >*length won't get set to 0 before returning. Don't worry, the out parameters are cleared early on (not enough -u, I know...)
* Updated for bitrot * Removed the consts (I only added them because I misread nsTArray.h) * Retained the removal of the sorting (although I thought I had to remove them so that I could add the consts, they're not actually needed anyway)
Attachment #295678 - Attachment is obsolete: true
Attachment #300330 - Flags: superreview?(bienvenu)
Attachment #295678 - Flags: superreview?(bienvenu)
Comment on attachment 300330 [details] [diff] [review] GetSelectedIndices patch I wish I remember why were sorting the view indices, but it looks like you're right that we don't need to.
Attachment #300330 - Flags: superreview?(bienvenu) → superreview+
Attached patch Most of the restSplinter Review
Most of this is just boilerplate substitution, but somehow I couldn't let PartitionSelectionByFolder off the hook without a rewrite. At one point I even considered storing the indices in an nsTArray<nsTArray<PRUint32> > .
Attachment #300713 - Flags: superreview?(bienvenu)
Attachment #300713 - Flags: review?(bienvenu)
Depends on: 415601
(In reply to comment #18) I applied the patch this morning and recompiled and turned the Remember Message preference again. No crash after two hours worth of testing. I haven't been run that long with normal mail usage in the past 12 days. So far I like it. Will post results after a full day in a few hours; but if others can apply the diff and test I think you'd appreciate the results! :)
(In reply to comment #19) ARGH! WRONG BUG!!! Comment 19 is not valid for this bug! :)
Comment on attachment 300713 [details] [diff] [review] Most of the rest thx, Neil. Can you just remove these comment lines? // m_idArray.RemoveAll(); - // m_flags.RemoveAll(); + // m_flags.Clear();
Attachment #300713 - Flags: superreview?(bienvenu)
Attachment #300713 - Flags: superreview+
Attachment #300713 - Flags: review?(bienvenu)
Attachment #300713 - Flags: review+
Attached patch Fix includes (obsolete) — Splinter Review
The only remaining consumer of nsUInt32Array is nsMsgKeyArray, which is being dealt with in a separate bug. Even then we can't simply remove the header file because three files are relying on it to include prmem.h; this patch fixes that. For nsMessenger.cpp the allocations are all wrong so I fixed them. For nsMsgDBView.cpp we need to be able to free the Allocate(d)RawSortKey. For nsMsgUtils.cpp the ns_MsgSA* functions should be replaced by nsCString...
Assignee: nick.kreeger → neil
Status: NEW → ASSIGNED
Attachment #303165 - Flags: review?(bienvenu)
Including some more allocator mismatches too.
Attachment #303165 - Attachment is obsolete: true
Attachment #303271 - Flags: review?(bienvenu)
Attachment #303165 - Flags: review?(bienvenu)
Comment on attachment 303271 [details] [diff] [review] Fix more includes getting rid of PR_CALLOC and +1 alloc size looks OK.
Attachment #303271 - Flags: review?(bienvenu) → review+
This bug is now fixed. Bug 413413 will actually remove nsUInt32ARray.* as nsMsgKeyArray still uses it.
Status: ASSIGNED → RESOLVED
Closed: 18 years ago
Resolution: --- → FIXED
Product: Core → MailNews Core
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: