Bug 642381, part 2: Rename LazilyConstructed to Maybe. r=luke

This commit is contained in:
Chris Jones 2011-04-28 17:48:51 -05:00
parent 0adf6af157
commit 6fd4cbff2d
12 changed files with 33 additions and 33 deletions

View File

@ -1886,8 +1886,8 @@ nsJSContext::CallEventHandler(nsISupports* aTarget, void *aScope, void *aHandler
return NS_ERROR_FAILURE;
}
js::LazilyConstructed<nsAutoPoolRelease> poolRelease;
js::LazilyConstructed<js::AutoArrayRooter> tvr;
js::Maybe<nsAutoPoolRelease> poolRelease;
js::Maybe<js::AutoArrayRooter> tvr;
// Use |target| as the scope for wrapping the arguments, since aScope is
// the safe scope in many cases, which isn't very useful. Wrapping aTarget
@ -2375,8 +2375,8 @@ nsJSContext::SetProperty(void *aTarget, const char *aPropName, nsISupports *aArg
JSAutoRequest ar(mContext);
js::LazilyConstructed<nsAutoPoolRelease> poolRelease;
js::LazilyConstructed<js::AutoArrayRooter> tvr;
js::Maybe<nsAutoPoolRelease> poolRelease;
js::Maybe<js::AutoArrayRooter> tvr;
nsresult rv;
rv = ConvertSupportsTojsvals(aArgs, GetNativeGlobal(), &argc,
@ -2416,8 +2416,8 @@ nsJSContext::ConvertSupportsTojsvals(nsISupports *aArgs,
void *aScope,
PRUint32 *aArgc,
jsval **aArgv,
js::LazilyConstructed<nsAutoPoolRelease> &aPoolRelease,
js::LazilyConstructed<js::AutoArrayRooter> &aRooter)
js::Maybe<nsAutoPoolRelease> &aPoolRelease,
js::Maybe<js::AutoArrayRooter> &aRooter)
{
nsresult rv = NS_OK;

View File

@ -51,7 +51,7 @@ class nsIXPConnectJSObjectHolder;
class nsAutoPoolRelease;
namespace js {
class AutoArrayRooter;
template <class> class LazilyConstructed;
template <class> class Maybe;
}
class nsJSContext : public nsIScriptContext,
@ -205,8 +205,8 @@ protected:
void *aScope,
PRUint32 *aArgc,
jsval **aArgv,
js::LazilyConstructed<nsAutoPoolRelease> &aPoolRelease,
js::LazilyConstructed<js::AutoArrayRooter> &aRooter);
js::Maybe<nsAutoPoolRelease> &aPoolRelease,
js::Maybe<js::AutoArrayRooter> &aRooter);
nsresult AddSupportsPrimitiveTojsvals(nsISupports *aArg, jsval *aArgv);

View File

@ -176,7 +176,7 @@ JetpackActorCommon::jsval_to_CompVariant(JSContext* cx, JSType type, jsval from,
if (type != JSTYPE_OBJECT)
return false;
js::LazilyConstructed<OpaqueSeenType> lost;
js::Maybe<OpaqueSeenType> lost;
if (!seen) {
lost.construct();
seen = lost.addr();
@ -337,7 +337,7 @@ JetpackActorCommon::jsval_from_CompVariant(JSContext* cx,
jsval* to,
OpaqueSeenType* seen)
{
js::LazilyConstructed<OpaqueSeenType> lost;
js::Maybe<OpaqueSeenType> lost;
if (!seen) {
lost.construct();
seen = lost.addr();

View File

@ -679,7 +679,7 @@ js_ContextIterator(JSRuntime *rt, JSBool unlocked, JSContext **iterp)
{
JSContext *cx = *iterp;
LazilyConstructed<AutoLockGC> lockIf;
Maybe<AutoLockGC> lockIf;
if (unlocked)
lockIf.construct(rt);
cx = js_ContextFromLinkField(cx ? cx->link.next : rt->contextList.next);

View File

@ -463,7 +463,7 @@ struct JS_FRIEND_API(JSCompartment) {
js::NativeIterCache nativeIterCache;
typedef js::LazilyConstructed<js::ToSourceCache> LazyToSourceCache;
typedef js::Maybe<js::ToSourceCache> LazyToSourceCache;
LazyToSourceCache toSourceCache;
JSCompartment(JSRuntime *rt);

View File

@ -838,7 +838,7 @@ js_watch_set(JSContext *cx, JSObject *obj, jsid id, JSBool strict, Value *vp)
}
{
LazilyConstructed<AutoShapeRooter> tvr;
Maybe<AutoShapeRooter> tvr;
if (needMethodSlotWrite)
tvr.construct(cx, needMethodSlotWrite);

View File

@ -2058,7 +2058,7 @@ fun_toStringHelper(JSContext *cx, JSObject *obj, uintN indent)
return NULL;
if (!indent) {
LazilyConstructed<ToSourceCache> &lazy = cx->compartment->toSourceCache;
Maybe<ToSourceCache> &lazy = cx->compartment->toSourceCache;
if (lazy.empty()) {
lazy.construct();

View File

@ -432,7 +432,7 @@ Arena<T> *
Chunk::allocateArena(JSContext *cx, unsigned thingKind)
{
#ifdef JS_THREADSAFE
LazilyConstructed<AutoLock> maybeLock;
Maybe<AutoLock> maybeLock;
if (cx->runtime->gcHelperThread.sweeping)
maybeLock.construct(info.chunkLock);
#endif
@ -459,7 +459,7 @@ Chunk::releaseArena(Arena<T> *arena)
{
JSRuntime *rt = info.runtime;
#ifdef JS_THREADSAFE
LazilyConstructed<AutoLock> maybeLock;
Maybe<AutoLock> maybeLock;
if (rt->gcHelperThread.sweeping)
maybeLock.construct(info.chunkLock);
#endif
@ -1265,7 +1265,7 @@ RunLastDitchGC(JSContext *cx)
JSRuntime *rt = cx->runtime;
METER(rt->gcStats.lastditch++);
#ifdef JS_THREADSAFE
LazilyConstructed<AutoUnlockAtomsCompartment> maybeUnlockAtomsCompartment;
Maybe<AutoUnlockAtomsCompartment> maybeUnlockAtomsCompartment;
if (cx->compartment == rt->atomsCompartment && rt->atomsCompartmentIsLocked)
maybeUnlockAtomsCompartment.construct(cx);
#endif

View File

@ -270,29 +270,29 @@ struct AlignedStorage2
/*
* Small utility for lazily constructing objects without using dynamic storage.
* When a LazilyConstructed<T> is constructed, it is |empty()|, i.e., no value
* of T has been constructed and no T destructor will be called when the
* LazilyConstructed<T> is destroyed. Upon calling |construct|, a T object will
* be constructed with the given arguments and that object will be destroyed
* when the owning LazilyConstructed<T> is destroyed.
* When a Maybe<T> is constructed, it is |empty()|, i.e., no value of T has
* been constructed and no T destructor will be called when the Maybe<T> is
* destroyed. Upon calling |construct|, a T object will be constructed with the
* given arguments and that object will be destroyed when the owning Maybe<T>
* is destroyed.
*
* N.B. GCC seems to miss some optimizations with LazilyConstructed and may
* generate extra branches/loads/stores. Use with caution on hot paths.
* N.B. GCC seems to miss some optimizations with Maybe and may generate extra
* branches/loads/stores. Use with caution on hot paths.
*/
template <class T>
class LazilyConstructed
class Maybe
{
AlignedStorage2<T> storage;
bool constructed;
T &asT() { return *storage.addr(); }
explicit LazilyConstructed(const LazilyConstructed &other);
const LazilyConstructed &operator=(const LazilyConstructed &other);
explicit Maybe(const Maybe &other);
const Maybe &operator=(const Maybe &other);
public:
LazilyConstructed() { constructed = false; }
~LazilyConstructed() { if (constructed) asT().~T(); }
Maybe() { constructed = false; }
~Maybe() { if (constructed) asT().~T(); }
bool empty() const { return !constructed; }

View File

@ -164,7 +164,7 @@ class AutoCompartment
JSObject * const target;
JSCompartment * const destination;
private:
LazilyConstructed<DummyFrameGuard> frame;
Maybe<DummyFrameGuard> frame;
FrameRegs regs;
AutoStringRooter input;
bool entered;

View File

@ -2222,7 +2222,7 @@ class CallMethodHelper
// to be declared as that would make the ctor and dtors run for each
// CallMethodHelper instantiation, and they're only needed in a
// fraction of all the calls that come through here.
js::LazilyConstructed<nsAutoString> mAutoString;
js::Maybe<nsAutoString> mAutoString;
jsval* const mArgv;
const PRUint32 mArgc;

View File

@ -786,7 +786,7 @@ nsLineLayout::ReflowFrame(nsIFrame* aFrame,
nscoord availableSpaceOnLine = psd->mRightEdge - psd->mX;
// Setup reflow state for reflowing the frame
js::LazilyConstructed<nsHTMLReflowState> reflowStateHolder;
js::Maybe<nsHTMLReflowState> reflowStateHolder;
if (!isText) {
reflowStateHolder.construct(mPresContext, *psd->mReflowState,
aFrame, availSize);