On Tuesday 2014-12-23 08:36 -0800, Eric Rescorla wrote:
> > Why not pass the raw pointer to the function?
> 
> 
> My general theory is that smart pointers, once boxed, should never be
> unboxed.
> The major arguments I see for unboxing is performance, but if you pass a
> ref,
> then you don't have the increment/decrement cycle.
> 
> 
> 
> >   That's what we do in most of the places in the code.
> >
> 
> Yes, I think this is unwise.

Our convention has always been to pass raw pointers, generally with
the assumption that the caller is expected to ensure the pointer
lives across the function call.

Passing references to smart pointers doesn't work if you need
implicit conversions from derived class to base class (e.g., if the
function takes Base*, and the caller has nsRefPtr<Derived>), which
is pretty important in many areas of our codebase.

Passing smart pointers (non-references) would cause tons of extra
reference count traffic, which is particularly problematic when the
reference-counting functions are virtual and/or threadsafe.

-David

-- 
𝄞   L. David Baron                         http://dbaron.org/   𝄂
𝄢   Mozilla                          https://www.mozilla.org/   𝄂
             Before I built a wall I'd ask to know
             What I was walling in or walling out,
             And to whom I was like to give offense.
               - Robert Frost, Mending Wall (1914)

Attachment: signature.asc
Description: Digital signature

_______________________________________________
dev-platform mailing list
dev-platform@lists.mozilla.org
https://lists.mozilla.org/listinfo/dev-platform

Reply via email to