Closed Bug 975823 Opened 10 years ago Closed 10 years ago

Clean up nsStreamConverterService

Categories

(Core :: Networking, defect)

defect
Not set
normal

Tracking

()

RESOLVED FIXED
mozilla31

People

(Reporter: mccr8, Assigned: mccr8)

References

Details

Attachments

(14 files, 1 obsolete file)

8.23 KB, patch
mcmanus
: review+
Details | Diff | Splinter Review
7.24 KB, patch
mcmanus
: review+
Details | Diff | Splinter Review
6.24 KB, patch
mcmanus
: review+
Details | Diff | Splinter Review
3.05 KB, patch
mcmanus
: review+
Details | Diff | Splinter Review
4.50 KB, patch
mcmanus
: review+
Details | Diff | Splinter Review
5.10 KB, patch
mcmanus
: review+
Details | Diff | Splinter Review
2.64 KB, patch
mcmanus
: review+
Details | Diff | Splinter Review
4.00 KB, patch
mcmanus
: review+
Details | Diff | Splinter Review
6.20 KB, patch
mcmanus
: review+
Details | Diff | Splinter Review
1.67 KB, patch
mcmanus
: review+
Details | Diff | Splinter Review
5.03 KB, patch
mcmanus
: review+
Details | Diff | Splinter Review
7.83 KB, patch
mcmanus
: review+
Details | Diff | Splinter Review
1.74 KB, patch
mcmanus
: review+
Details | Diff | Splinter Review
2.24 KB, patch
mcmanus
: review+
Details | Diff | Splinter Review
The code in this file is pretty old, and there are some things that can be cleaned up.

1. Some trailing whitespace.
2. Tons of null checks for the return value of infallible new.
3. The two different hashtables in this file use the same type for their data, for no reason.

The combination of 2 and 3 allows a lot of simplifications.
Patrick, do you have a suggestion for who could review these changes to nsStreamConverterService, or should I just pick a random networking peer?  There are a lot of patches here, but each one makes a small mechanical change, and shouldn't really require a deep understanding of whatever this class is doing.
Flags: needinfo?(mcmanus)
I'll take them
Flags: needinfo?(mcmanus)
Thanks!  In part 7, SCTableData ends up as a typedef, which I don't inline.  Instead, I'm going to do that in bug 972593, because the conversion to a modern hash table eliminates a bunch of casts that mention SCTableData, so it makes the replacement a little nicer.
Attachment #8391885 - Flags: review+
Attachment #8391886 - Flags: review+
Andrew - I appreciate the legacy cleanup. We've got a lot of that hanging around. You deserve an award for turning the patch series into a choose-your-own-adventure (best-path) novel..
Attachment #8391887 - Flags: review+
Attachment #8391888 - Flags: review+
Attachment #8391889 - Flags: review+
Attachment #8391890 - Flags: review+
Attachment #8391891 - Flags: review+
Comment on attachment 8391892 [details] [diff] [review]
part 8 - Inline nsStreamConverterService::Init which is now infallible.

Review of attachment 8391892 [details] [diff] [review]:
-----------------------------------------------------------------

::: netwerk/streamconv/src/nsStreamConverterService.cpp
@@ +52,5 @@
>  // Adjacency list data class.
>  typedef nsCOMArray<nsIAtom> SCTableData;
>  
> +// Delete all the entries in the adjacency list
> +static bool DeleteAdjacencyEntry(nsHashKey *aKey, void *aData, void* closure) {

nit *closure not * closure.. but you're just moving the code so don't fix if its a pain.
Attachment #8391892 - Flags: review+
Attachment #8391894 - Flags: review+
Attachment #8391895 - Flags: review+
Attachment #8391896 - Flags: review+
Attachment #8391897 - Flags: review+
Attachment #8391898 - Flags: review+
(In reply to Patrick McManus [:mcmanus] from comment #18)
> Andrew - I appreciate the legacy cleanup. We've got a lot of that hanging
> around. You deserve an award for turning the patch series into a
> choose-your-own-adventure (best-path) novel..

Thanks!  And thanks for all of the reviews.  I just wish I knew why it did this in the first place. ;)
(In reply to Patrick McManus [:mcmanus] from comment #19)
> nit *closure not * closure.. but you're just moving the code so don't fix if
> its a pain.

That method actually gets deleted in the hash table conversion, so I'll just leave the * alone.
This is leaking a small number of nsCStringKey and nsHashKey.  That's what I get for failing to push this to try without the hash table conversion on top of it!  I'm sure this will be easy to fix, so I'll look into it tomorrow.
This is kind of awesome.  Most hash table keys are allocated on the stack, then they get added to the hashtable, which clones the key.  These two are allocated on the heap.  Before my part 4 patch here, SCTableData would store a pointer to that heap allocated key, do nothing with it, until the entry went away, when it would delete the key, avoiding a leak.  I removed the pointer to the key in part 4, because we never used it, so these heap allocated keys started leaking.  The solution is just to not be weird and allocate them on the stack like everything else.  I'll land this folded into part 4.

try run is green: https://tbpl.mozilla.org/?tree=Try&rev=facff5057fe4
Attachment #8394426 - Flags: review?(mcmanus)
Somebody went to a lot of effort to keep around pointers to these keys in SCTableData, so they must have been used at some point...
Comment on attachment 8394426 [details] [diff] [review]
part 4b - Don't pointlessly create new hash table keys.

Review of attachment 8394426 [details] [diff] [review]:
-----------------------------------------------------------------

awesome. it's like being a forensic programmer some days.
Attachment #8394426 - Flags: review?(mcmanus) → review+
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: