Closed
Bug 213602
Opened 22 years ago
Closed 12 years ago
Switch some users of NS_GetWeakReference over to do_GetWeakReference
Categories
(Core :: XPCOM, defect)
Core
XPCOM
Tracking
()
RESOLVED
INCOMPLETE
People
(Reporter: jag+mozilla, Unassigned)
Details
Attachments
(3 files, 1 obsolete file)
71.02 KB,
patch
|
bzbarsky
:
review+
dbaron
:
superreview+
|
Details | Diff | Splinter Review |
3.62 KB,
patch
|
dbaron
:
review+
darin.moz
:
superreview+
asa
:
approval1.5b-
|
Details | Diff | Splinter Review |
1.04 KB,
patch
|
jst
:
review+
dbaron
:
superreview+
asa
:
approval1.5b-
|
Details | Diff | Splinter Review |
Reporter | ||
Comment 1•22 years ago
|
||
Reporter | ||
Updated•22 years ago
|
Attachment #128364 -
Flags: superreview?(dbaron)
Attachment #128364 -
Flags: review?(bzbarsky)
Comment on attachment 128364 [details] [diff] [review]
switch
sr=dbaron. Hopefully the performance hit will be insignificant.
Attachment #128364 -
Flags: superreview?(dbaron) → superreview+
![]() |
||
Comment 3•22 years ago
|
||
Comment on attachment 128364 [details] [diff] [review]
switch
r=bzbarsky
Attachment #128364 -
Flags: review?(bzbarsky) → review+
Reporter | ||
Comment 4•22 years ago
|
||
I guess I should look at the performance aspect a little more, though it seems
like both construct a nsGetWeakReference object and use its operator() to do the
work.
Reporter | ||
Comment 5•22 years ago
|
||
// non-inlined:
nsIWeakReference*
NS_GetWeakReference( nsISupports* aInstancePtr, nsresult* aErrorPtr = 0 )
{
void* result = 0;
nsGetWeakReference(aInstancePtr, aErrorPtr)(NS_GET_IID(nsIWeakReference),
&result);
return NS_STATIC_CAST(nsIWeakReference*, result);
}
vs.
// inlined:
const nsGetWeakReference
do_GetWeakReference( nsISupports* aRawPtr, nsresult* error = 0 )
{
return nsGetWeakReference(aRawPtr, error);
}
NS_GetWeakReference can by-pass a virtual function call because it calls
operator() on a concrete object vs. nsCOMPtr calling it on an interface. I'll
have to compile and see what effect the other variables (non-inline vs. inline,
return value vs. out param) have. If there actually is a non-negligible impact,
could we change do_GetWeakReference to be (the equivalent of)?
already_AddRefed<nsIWeakReference>
do_GetWeakReference( nsISupports* aRawPtr, nsresult* error = 0 )
{
return NS_GetWeakReference(aRawPtr, error);
}
Oh, I didn't realize NS_GetWeakReference was already using nsGetWeakReference.
Reporter | ||
Comment 7•22 years ago
|
||
This did increase the codesize a little 'coz of nsGetWeakReference constructor
getting inlined, and the nsCOMPtr constructor changing, adding a NS_GET_IID.
Reporter | ||
Comment 8•22 years ago
|
||
Well, not the nsCOMPtr constructor changing, but rather a change in which
nsCOMPtr constructor we call.
Status: NEW → ASSIGNED
Reporter | ||
Comment 9•22 years ago
|
||
Alternatively I could reverse this and implement NS_GetWeakReference in terms
of do_GetWeakReference (does already_AddRefed<...> play nice with NS_COM?).
Reporter | ||
Updated•22 years ago
|
Attachment #128964 -
Flags: superreview?(darin)
Attachment #128964 -
Flags: review?(dbaron)
Attachment #128964 -
Flags: review?(dbaron) → review+
Reporter | ||
Comment 10•22 years ago
|
||
Changing do_GetWeakReference to return already_AddRefed<nsIWeakReference>
nsPrefBranch.cpp to break. The old code was doing an implicit upcast from
nsIWeakReference to nsISupports.
Reporter | ||
Comment 11•22 years ago
|
||
Comment on attachment 128971 [details] [diff] [review]
I had to make this change
Btw, in a debug build the previous patch turned out to increase codesize, not
decrease it. Looking at optimized now.
Attachment #128971 -
Flags: review?(dbaron)
Comment on attachment 128971 [details] [diff] [review]
I had to make this change
Why did you need to change all this? There's no need for the canonical
nsISupports pointer here, is there?
Reporter | ||
Comment 13•22 years ago
|
||
I think it's needed when the observer is removed in ::RemoveObserver:
if (pCallback->pObserver == observerRef) {
but correct me if I'm wrong.
Updated•22 years ago
|
Attachment #128964 -
Flags: superreview?(darin) → superreview+
Reporter | ||
Comment 14•22 years ago
|
||
Comment on attachment 128971 [details] [diff] [review]
I had to make this change
Never mind, this would cause us to assert a lot in debug builds. Perhaps we
could just get rid of the assert and make this more like QueryInterface (i.e.
QI'ing to a non-supported interface isn't considered a bad thing), where a null
result tells us whether the do_GetWeakReference succeeded.
Attachment #128971 -
Attachment is obsolete: true
Attachment #128971 -
Flags: review?(dbaron)
Reporter | ||
Comment 15•22 years ago
|
||
I'd like to go with this patch for now. dbaron, jst and I have discussed
several solutions for this that would let us avoid duplicating the QI to
nsISupportsWeakReference (in the Add/RemoveObserver code and in the
*_GetWeakReference code), but I don't think we've settled on one solution
(unless we settled on two yesterday).
Reporter | ||
Updated•22 years ago
|
Attachment #129305 -
Flags: superreview?(dbaron)
Attachment #129305 -
Flags: review?(jst)
Reporter | ||
Comment 16•22 years ago
|
||
Oh, so here are the thoughts (should probably go to a new bug, really):
1) Just remove the assertion in NS_GetWeakReference, trying to get a weak
reference from something that doesn't support it is okay, we'll return nsnull
and the appropriate error value to indicate it's not supported (more like how
QueryInterface works).
2) Add a second version of NS_GetWeakReference and do_GetWeakReference that take
a nsISupportsWeakReference* so the client itself can QI to find out if the
object supports weak references and avoid doing an (in this case) redundant QI.
Attachment #129305 -
Flags: superreview?(dbaron) → superreview+
Comment 17•22 years ago
|
||
Comment on attachment 129305 [details] [diff] [review]
Smaller fix, more like what the other places do
- observerRef = do_GetWeakReference(weakRefFactory);
+ observerRef = dont_AddRef(NS_STATIC_CAST(nsISupports*,
NS_GetWeakReference(weakRefFactory)));
NS_GetWeakReference() returns an nsIWeakReference, which inherits directly from
nsISupports. So why bother casting, the compiler will do that for you.
- observerRef = do_GetWeakReference(aObserver);
+ observerRef = dont_AddRef(NS_STATIC_CAST(nsISupports*,
NS_GetWeakReference(aObserver)));
Same here.
r=jst either way.
Attachment #129305 -
Flags: review?(jst) → review+
The cast is needed because nsCOMPtr<T>& operator=( const already_AddRefed<T>&
rhs ) requires an already_AddRefed<T> of the same type.
Reporter | ||
Comment 19•22 years ago
|
||
Comment on attachment 128964 [details] [diff] [review]
No need for nsGetWeakReference as a nsCOMPtr_helper
Requesting a=
Small change, should make us a little smaller here and there.
Attachment #128964 -
Flags: approval1.5b?
Reporter | ||
Comment 20•22 years ago
|
||
Comment on attachment 129305 [details] [diff] [review]
Smaller fix, more like what the other places do
Requesting a=
Need this to make it compile.
Attachment #129305 -
Flags: approval1.5b?
Comment 21•22 years ago
|
||
Do we need both of these patches? When this gets landed let's make sure we watch
for any performance inpact.
Comment 22•22 years ago
|
||
Comment on attachment 128964 [details] [diff] [review]
No need for nsGetWeakReference as a nsCOMPtr_helper
->1.6a
Attachment #128964 -
Flags: approval1.5b? → approval1.5b-
Comment 23•22 years ago
|
||
Comment on attachment 129305 [details] [diff] [review]
Smaller fix, more like what the other places do
->1.6a
Attachment #129305 -
Flags: approval1.5b? → approval1.5b-
Updated•19 years ago
|
Assignee: jag → nobody
Status: ASSIGNED → NEW
QA Contact: scc → xpcom
Updated•12 years ago
|
Status: NEW → RESOLVED
Closed: 12 years ago
Resolution: --- → INCOMPLETE
You need to log in
before you can comment on or make changes to this bug.
Description
•