Closed Bug 717066 Opened 14 years ago Closed 14 years ago

Remove unnecessary nsresult return value from nsGenericHTMLElement::GetLayoutHistoryAndKey

Categories

(Core :: DOM: Core & HTML, defect)

defect
Not set
normal

Tracking

()

RESOLVED FIXED
mozilla12

People

(Reporter: dholbert, Assigned: jhk)

Details

(Whiteboard: [good first bug][mentor=Ms2ger][lang=c++])

Attachments

(1 file, 3 obsolete files)

Ever since it was first checked in (in bug 108309 back in 2002), the method nsGenericHTMLElement::GetLayoutHistoryAndKey has had a nsresult return value that we ignore everywhere it's called. (See bug 717004 comment 0). From the callers' perspectives, GetLayoutHistoryAndKey indicates failure by leaving its |aHistory| argument untouched (e.g. as nsnull). Since it's already got that de-facto method of indicating failure, we should just drop the nsresult return value.
OS: Linux → All
Hardware: x86_64 → All
There are only two callers of GetLayoutHistoryAndKey. One is effectively: GetLayoutHistoryAndKey(..., getter_AddRefs(history)); if (history) { [bulk of the method] } return; and the other is effectively: GetLayoutHistoryAndKey(..., getter_AddRefs(history)); if (!history) { return false; } So in both cases, we only care about what GetLayoutHistoryAndKey did if it returns a non-null |history| pointer. Volkmar pointed out in bug 717004 comment 10 that a null |history| pointer doesn't necessarily indicate failure, but I don't think that really matters from the clients' perspectives.
Wouldn't be better to return an already_Addrefed object insead of having an out param?
Sure, that sounds reasonable to me.
Whiteboard: [good first bug][mentor=Ms2ger][lang=c++]
Attached patch Patch (obsolete) — Splinter Review
Assignee: nobody → jigneshhk1992
Attachment #588386 - Flags: review?(Ms2ger)
Attached patch Patch (obsolete) — Splinter Review
Attachment #588386 - Attachment is obsolete: true
Attachment #588386 - Flags: review?(Ms2ger)
Attachment #588387 - Flags: review?(Ms2ger)
Why not returning an already_Addrefed object?
That works, but I'd prefer changing the signature to already_AddRefed<nsILayoutHistoryState> GetLayoutHistoryAndKey(nsGenericHTMLElement* aContent, bool aRead, nsACString& aKey); so you would start the function with nsCOMPtr<nsILayoutHistoryState> history = doc->GetLayoutHistoryState(); change the references to |*aHistory| to |history|, get rid of the NS_RELEASEs, and return either |nsnull| (in case of failure), or |history.forget()| (in case of success). Want to take a shot at that?
> Want to take a shot at that? Definitely:)
Attached patch Patch (obsolete) — Splinter Review
Attachment #588387 - Attachment is obsolete: true
Attachment #588387 - Flags: review?(Ms2ger)
Attachment #588402 - Flags: review?(Ms2ger)
Comment on attachment 588402 [details] [diff] [review] Patch Review of attachment 588402 [details] [diff] [review]: ----------------------------------------------------------------- Looks good, just a few small nits to change: ::: content/html/content/src/nsGenericHTMLElement.cpp @@ +1551,5 @@ > nsresult result = NS_OK; > > nsCOMPtr<nsILayoutHistoryState> history; > nsCAutoString key; > + history = GetLayoutHistoryAndKey(aContent, false, key); Make this nsCAutoString key; nsCOMPtr<nsILayoutHistoryState> history = GetLayoutHistoryAndKey(aContent, false, key); @@ +1589,3 @@ > } > > + if (aRead && !(history)->HasStates()) { The ()s around history can go now. @@ +1619,5 @@ > nsIFormControl* aControl) > { > nsCOMPtr<nsILayoutHistoryState> history; > nsCAutoString key; > + history = GetLayoutHistoryAndKey(aContent, true, key); Same here ::: content/html/content/src/nsGenericHTMLElement.h @@ +472,5 @@ > * @param aKey the key (out param) > */ > + static already_AddRefed<nsILayoutHistoryState> GetLayoutHistoryAndKey(nsGenericHTMLElement* aContent, > + bool aRead, > + nsACString& aKey); These lines are getting too long now, please move |static already_AddRefed<nsILayoutHistoryState>| onto a line by itself.
Attachment #588402 - Flags: review?(Ms2ger) → review+
Comment on attachment 588402 [details] [diff] [review] Patch Review of attachment 588402 [details] [diff] [review]: ----------------------------------------------------------------- ::: content/html/content/src/nsGenericHTMLElement.cpp @@ +1551,5 @@ > nsresult result = NS_OK; > > nsCOMPtr<nsILayoutHistoryState> history; > nsCAutoString key; > + history = GetLayoutHistoryAndKey(aContent, false, key); I would write: nsCOMPtr<...> history = GetLayoutHistoryAndKey(...); @@ +1619,5 @@ > nsIFormControl* aControl) > { > nsCOMPtr<nsILayoutHistoryState> history; > nsCAutoString key; > + history = GetLayoutHistoryAndKey(aContent, true, key); I would write: nsCOMPtr<...> history = GetLayoutHistoryAndKey(...);
Attachment #588402 - Flags: review+ → review?(Ms2ger)
Comment on attachment 588402 [details] [diff] [review] Patch Yes, thanks Mounir
Attachment #588402 - Flags: review?(Ms2ger) → review+
Attached patch PatchSplinter Review
Attachment #588402 - Attachment is obsolete: true
Attachment #588407 - Flags: review?(Ms2ger)
Jignesh, you don't have to re-ask a review if someone r+ a patch and ask you to do a few minor changes.
Attachment #588407 - Flags: review?(Ms2ger)
Summary: Make nsGenericHTMLElement::GetLayoutHistoryAndKey return void → Remove unnecessary nsresult return value from nsGenericHTMLElement::GetLayoutHistoryAndKey
Checkin-needed.
Flags: in-testsuite-
Keywords: checkin-needed
Target Milestone: --- → mozilla12
Status: NEW → RESOLVED
Closed: 14 years ago
Resolution: --- → FIXED
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: