зеркало из https://github.com/mozilla/gecko-dev.git
Bug 909977 - Rename mozilla::Move to mozilla::OldMove, and make mozilla::Move a synonym for std::move(). r=waldo
--HG-- extra : rebase_source : 7b3bb02cc8cbc0ad6721c6c3895564d9567b8ddb
This commit is contained in:
Родитель
7c75ee0aeb
Коммит
66f7416cab
|
@ -8,6 +8,7 @@
|
|||
|
||||
#include "nsChromeRegistry.h"
|
||||
#include "nsVoidArray.h"
|
||||
#include "mozilla/Move.h"
|
||||
|
||||
namespace mozilla {
|
||||
namespace dom {
|
||||
|
@ -126,8 +127,8 @@ class nsChromeRegistryChrome : public nsChromeRegistry
|
|||
typedef nsURIHashKey::KeyTypePointer KeyTypePointer;
|
||||
|
||||
OverlayListEntry(KeyTypePointer aKey) : nsURIHashKey(aKey) { }
|
||||
OverlayListEntry(OverlayListEntry& toCopy) : nsURIHashKey(toCopy),
|
||||
mArray(toCopy.mArray) { }
|
||||
OverlayListEntry(OverlayListEntry&& toMove) : nsURIHashKey(mozilla::Move(toMove)),
|
||||
mArray(mozilla::Move(toMove.mArray)) { }
|
||||
~OverlayListEntry() { }
|
||||
|
||||
void AddURI(nsIURI* aURI);
|
||||
|
|
|
@ -605,11 +605,12 @@ private:
|
|||
|
||||
FontTableHashEntry(KeyTypePointer aTag)
|
||||
: KeyClass(aTag), mBlob() { }
|
||||
// Copying transfers blob association.
|
||||
FontTableHashEntry(FontTableHashEntry& toCopy)
|
||||
: KeyClass(toCopy), mBlob(toCopy.mBlob)
|
||||
|
||||
FontTableHashEntry(FontTableHashEntry&& toMove)
|
||||
: KeyClass(mozilla::Move(toMove))
|
||||
, mBlob(mozilla::Move(toMove.mBlob))
|
||||
{
|
||||
toCopy.mBlob = nullptr;
|
||||
toMove.mBlob = nullptr;
|
||||
}
|
||||
|
||||
~FontTableHashEntry() { Clear(); }
|
||||
|
|
|
@ -138,18 +138,18 @@ class HashMap
|
|||
template<typename KeyInput, typename ValueInput>
|
||||
bool add(AddPtr &p, const KeyInput &k, const ValueInput &v) {
|
||||
Entry e(k, v);
|
||||
return impl.add(p, mozilla::Move(e));
|
||||
return impl.add(p, mozilla::OldMove(e));
|
||||
}
|
||||
|
||||
bool add(AddPtr &p, const Key &k) {
|
||||
Entry e(k, Value());
|
||||
return impl.add(p, mozilla::Move(e));
|
||||
return impl.add(p, mozilla::OldMove(e));
|
||||
}
|
||||
|
||||
template<typename KeyInput, typename ValueInput>
|
||||
bool relookupOrAdd(AddPtr &p, const KeyInput &k, const ValueInput &v) {
|
||||
Entry e(k, v);
|
||||
return impl.relookupOrAdd(p, k, mozilla::Move(e));
|
||||
return impl.relookupOrAdd(p, k, mozilla::OldMove(e));
|
||||
}
|
||||
|
||||
// |all()| returns a Range containing |count()| elements. E.g.:
|
||||
|
@ -231,7 +231,7 @@ class HashMap
|
|||
template<typename KeyInput, typename ValueInput>
|
||||
bool putNew(const KeyInput &k, const ValueInput &v) {
|
||||
Entry e(k, v);
|
||||
return impl.putNew(k, mozilla::Move(e));
|
||||
return impl.putNew(k, mozilla::OldMove(e));
|
||||
}
|
||||
|
||||
// Add (k,defaultValue) if |k| is not found. Return a false-y Ptr on oom.
|
||||
|
@ -258,8 +258,8 @@ class HashMap
|
|||
}
|
||||
|
||||
// HashMap is movable
|
||||
HashMap(mozilla::MoveRef<HashMap> rhs) : impl(mozilla::Move(rhs->impl)) {}
|
||||
void operator=(mozilla::MoveRef<HashMap> rhs) { impl = mozilla::Move(rhs->impl); }
|
||||
HashMap(mozilla::MoveRef<HashMap> rhs) : impl(mozilla::OldMove(rhs->impl)) {}
|
||||
void operator=(mozilla::MoveRef<HashMap> rhs) { impl = mozilla::OldMove(rhs->impl); }
|
||||
|
||||
private:
|
||||
// HashMap is not copyable or assignable
|
||||
|
@ -457,8 +457,8 @@ class HashSet
|
|||
}
|
||||
|
||||
// HashSet is movable
|
||||
HashSet(mozilla::MoveRef<HashSet> rhs) : impl(mozilla::Move(rhs->impl)) {}
|
||||
void operator=(mozilla::MoveRef<HashSet> rhs) { impl = mozilla::Move(rhs->impl); }
|
||||
HashSet(mozilla::MoveRef<HashSet> rhs) : impl(mozilla::OldMove(rhs->impl)) {}
|
||||
void operator=(mozilla::MoveRef<HashSet> rhs) { impl = mozilla::OldMove(rhs->impl); }
|
||||
|
||||
private:
|
||||
// HashSet is not copyable or assignable
|
||||
|
@ -585,7 +585,7 @@ class HashMapEntry
|
|||
HashMapEntry(const KeyInput &k, const ValueInput &v) : key(k), value(v) {}
|
||||
|
||||
HashMapEntry(mozilla::MoveRef<HashMapEntry> rhs)
|
||||
: key(mozilla::Move(rhs->key)), value(mozilla::Move(rhs->value)) { }
|
||||
: key(mozilla::OldMove(rhs->key)), value(mozilla::OldMove(rhs->value)) { }
|
||||
|
||||
typedef Key KeyType;
|
||||
typedef Value ValueType;
|
||||
|
@ -1169,7 +1169,7 @@ class HashTable : private AllocPolicy
|
|||
for (Entry *src = oldTable, *end = src + oldCap; src < end; ++src) {
|
||||
if (src->isLive()) {
|
||||
HashNumber hn = src->getKeyHash();
|
||||
findFreeEntry(hn).setLive(hn, mozilla::Move(src->get()));
|
||||
findFreeEntry(hn).setLive(hn, mozilla::OldMove(src->get()));
|
||||
src->destroy();
|
||||
}
|
||||
}
|
||||
|
@ -1467,10 +1467,10 @@ class HashTable : private AllocPolicy
|
|||
JS_ASSERT(table);
|
||||
mozilla::ReentrancyGuard g(*this);
|
||||
JS_ASSERT(p.found());
|
||||
typename HashTableEntry<T>::NonConstT t(mozilla::Move(*p));
|
||||
typename HashTableEntry<T>::NonConstT t(mozilla::OldMove(*p));
|
||||
HashPolicy::setKey(t, const_cast<Key &>(k));
|
||||
remove(*p.entry_);
|
||||
putNewInfallible(l, mozilla::Move(t));
|
||||
putNewInfallible(l, mozilla::OldMove(t));
|
||||
}
|
||||
|
||||
void rekeyAndMaybeRehash(Ptr p, const Lookup &l, const Key &k)
|
||||
|
|
|
@ -277,8 +277,8 @@ struct ZoneStats : js::ZoneStatsPod
|
|||
|
||||
ZoneStats(mozilla::MoveRef<ZoneStats> other)
|
||||
: ZoneStatsPod(other),
|
||||
strings(mozilla::Move(other->strings)),
|
||||
notableStrings(mozilla::Move(other->notableStrings))
|
||||
strings(mozilla::OldMove(other->strings)),
|
||||
notableStrings(mozilla::OldMove(other->notableStrings))
|
||||
{}
|
||||
|
||||
// Add other's numbers to this object's numbers. Both objects'
|
||||
|
|
|
@ -25,7 +25,7 @@ using namespace js;
|
|||
|
||||
using mozilla::DoubleIsInt32;
|
||||
using mozilla::IsNaN;
|
||||
using mozilla::Move;
|
||||
using mozilla::OldMove;
|
||||
using mozilla::MoveRef;
|
||||
|
||||
|
||||
|
@ -610,7 +610,7 @@ class OrderedHashTable
|
|||
if (!Ops::isEmpty(Ops::getKey(rp->element))) {
|
||||
HashNumber h = prepareHash(Ops::getKey(rp->element)) >> hashShift;
|
||||
if (rp != wp)
|
||||
wp->element = Move(rp->element);
|
||||
wp->element = OldMove(rp->element);
|
||||
wp->chain = hashTable[h];
|
||||
hashTable[h] = wp;
|
||||
wp++;
|
||||
|
@ -657,7 +657,7 @@ class OrderedHashTable
|
|||
for (Data *p = data, *end = data + dataLength; p != end; p++) {
|
||||
if (!Ops::isEmpty(Ops::getKey(p->element))) {
|
||||
HashNumber h = prepareHash(Ops::getKey(p->element)) >> newHashShift;
|
||||
new (wp) Data(Move(p->element), newHashTable[h]);
|
||||
new (wp) Data(OldMove(p->element), newHashTable[h]);
|
||||
newHashTable[h] = wp;
|
||||
wp++;
|
||||
}
|
||||
|
@ -698,14 +698,14 @@ class OrderedHashMap
|
|||
}
|
||||
|
||||
void operator=(MoveRef<Entry> rhs) {
|
||||
const_cast<Key &>(key) = Move(rhs->key);
|
||||
value = Move(rhs->value);
|
||||
const_cast<Key &>(key) = OldMove(rhs->key);
|
||||
value = OldMove(rhs->value);
|
||||
}
|
||||
|
||||
public:
|
||||
Entry() : key(), value() {}
|
||||
Entry(const Key &k, const Value &v) : key(k), value(v) {}
|
||||
Entry(MoveRef<Entry> rhs) : key(Move(rhs->key)), value(Move(rhs->value)) {}
|
||||
Entry(MoveRef<Entry> rhs) : key(OldMove(rhs->key)), value(OldMove(rhs->value)) {}
|
||||
|
||||
const Key key;
|
||||
Value value;
|
||||
|
|
|
@ -44,7 +44,7 @@ using mozilla::HashGeneric;
|
|||
using mozilla::IsNaN;
|
||||
using mozilla::IsNegativeZero;
|
||||
using mozilla::Maybe;
|
||||
using mozilla::Move;
|
||||
using mozilla::OldMove;
|
||||
using mozilla::MoveRef;
|
||||
|
||||
static const size_t LIFO_ALLOC_PRIMARY_CHUNK_SIZE = 1 << 12;
|
||||
|
@ -664,7 +664,7 @@ class Signature
|
|||
Signature(MoveRef<VarTypeVector> argTypes, RetType retType)
|
||||
: argTypes_(argTypes), retType_(retType) {}
|
||||
Signature(MoveRef<Signature> rhs)
|
||||
: argTypes_(Move(rhs->argTypes_)), retType_(rhs->retType_) {}
|
||||
: argTypes_(OldMove(rhs->argTypes_)), retType_(rhs->retType_) {}
|
||||
|
||||
bool copy(const Signature &rhs) {
|
||||
if (!argTypes_.resize(rhs.argTypes_.length()))
|
||||
|
@ -678,7 +678,7 @@ class Signature
|
|||
bool appendArg(VarType type) { return argTypes_.append(type); }
|
||||
VarType arg(unsigned i) const { return argTypes_[i]; }
|
||||
const VarTypeVector &args() const { return argTypes_; }
|
||||
MoveRef<VarTypeVector> extractArgs() { return Move(argTypes_); }
|
||||
MoveRef<VarTypeVector> extractArgs() { return OldMove(argTypes_); }
|
||||
|
||||
RetType retType() const { return retType_; }
|
||||
};
|
||||
|
@ -1077,8 +1077,8 @@ class MOZ_STACK_CLASS ModuleCompiler
|
|||
{}
|
||||
|
||||
FuncPtrTable(MoveRef<FuncPtrTable> rhs)
|
||||
: sig_(Move(rhs->sig_)), mask_(rhs->mask_), globalDataOffset_(rhs->globalDataOffset_),
|
||||
elems_(Move(rhs->elems_))
|
||||
: sig_(OldMove(rhs->sig_)), mask_(rhs->mask_), globalDataOffset_(rhs->globalDataOffset_),
|
||||
elems_(OldMove(rhs->elems_))
|
||||
{}
|
||||
|
||||
Signature &sig() { return sig_; }
|
||||
|
@ -1102,7 +1102,7 @@ class MOZ_STACK_CLASS ModuleCompiler
|
|||
ExitDescriptor(PropertyName *name, MoveRef<Signature> sig)
|
||||
: name_(name), sig_(sig) {}
|
||||
ExitDescriptor(MoveRef<ExitDescriptor> rhs)
|
||||
: name_(rhs->name_), sig_(Move(rhs->sig_))
|
||||
: name_(rhs->name_), sig_(OldMove(rhs->sig_))
|
||||
{}
|
||||
const Signature &sig() const {
|
||||
return sig_;
|
||||
|
@ -1401,7 +1401,7 @@ class MOZ_STACK_CLASS ModuleCompiler
|
|||
if (!module_->addFuncPtrTable(/* numElems = */ mask + 1, &globalDataOffset))
|
||||
return false;
|
||||
FuncPtrTable tmpTable(cx_, sig, mask, globalDataOffset);
|
||||
if (!funcPtrTables_.append(Move(tmpTable)))
|
||||
if (!funcPtrTables_.append(OldMove(tmpTable)))
|
||||
return false;
|
||||
*table = &funcPtrTables_.back();
|
||||
return true;
|
||||
|
@ -1452,7 +1452,7 @@ class MOZ_STACK_CLASS ModuleCompiler
|
|||
argCoercions[i] = args[i].toCoercion();
|
||||
AsmJSModule::ReturnType retType = func->sig().retType().toModuleReturnType();
|
||||
return module_->addExportedFunction(func->name(), maybeFieldName,
|
||||
Move(argCoercions), retType);
|
||||
OldMove(argCoercions), retType);
|
||||
}
|
||||
bool addExit(unsigned ffiIndex, PropertyName *name, MoveRef<Signature> sig, unsigned *exitIndex) {
|
||||
ExitDescriptor exitDescriptor(name, sig);
|
||||
|
@ -1463,7 +1463,7 @@ class MOZ_STACK_CLASS ModuleCompiler
|
|||
}
|
||||
if (!module_->addExit(ffiIndex, exitIndex))
|
||||
return false;
|
||||
return exits_.add(p, Move(exitDescriptor), *exitIndex);
|
||||
return exits_.add(p, OldMove(exitDescriptor), *exitIndex);
|
||||
}
|
||||
bool addGlobalAccess(AsmJSGlobalAccess access) {
|
||||
return globalAccesses_.append(access);
|
||||
|
@ -2508,7 +2508,7 @@ class FunctionCompiler
|
|||
typename Map::AddPtr p = map->lookupForAdd(key);
|
||||
if (!p) {
|
||||
BlockVector empty(m().cx());
|
||||
if (!map->add(p, key, Move(empty)))
|
||||
if (!map->add(p, key, OldMove(empty)))
|
||||
return false;
|
||||
}
|
||||
if (!p->value.append(curBlock_))
|
||||
|
@ -3385,7 +3385,7 @@ CheckInternalCall(FunctionCompiler &f, ParseNode *callNode, PropertyName *callee
|
|||
return false;
|
||||
|
||||
ModuleCompiler::Func *callee;
|
||||
if (!CheckFunctionSignature(f.m(), callNode, Move(call.sig()), calleeName, &callee))
|
||||
if (!CheckFunctionSignature(f.m(), callNode, OldMove(call.sig()), calleeName, &callee))
|
||||
return false;
|
||||
|
||||
if (!f.internalCall(*callee, call, def))
|
||||
|
@ -3461,7 +3461,7 @@ CheckFuncPtrCall(FunctionCompiler &f, ParseNode *callNode, RetType retType, MDef
|
|||
return false;
|
||||
|
||||
ModuleCompiler::FuncPtrTable *table;
|
||||
if (!CheckFuncPtrTableAgainstExisting(f.m(), tableNode, name, Move(call.sig()), mask, &table))
|
||||
if (!CheckFuncPtrTableAgainstExisting(f.m(), tableNode, name, OldMove(call.sig()), mask, &table))
|
||||
return false;
|
||||
|
||||
if (!f.funcPtrCall(*table, indexDef, call, def))
|
||||
|
@ -3490,7 +3490,7 @@ CheckFFICall(FunctionCompiler &f, ParseNode *callNode, unsigned ffiIndex, RetTyp
|
|||
return false;
|
||||
|
||||
unsigned exitIndex;
|
||||
if (!f.m().addExit(ffiIndex, calleeName, Move(call.sig()), &exitIndex))
|
||||
if (!f.m().addExit(ffiIndex, calleeName, OldMove(call.sig()), &exitIndex))
|
||||
return false;
|
||||
|
||||
if (!f.ffiCall(exitIndex, call, retType.toMIRType(), def))
|
||||
|
@ -4674,9 +4674,9 @@ CheckFunction(ModuleCompiler &m, LifoAlloc &lifo, MIRGenerator **mir, ModuleComp
|
|||
if (!CheckReturnType(f, lastNonEmptyStmt, retType))
|
||||
return false;
|
||||
|
||||
Signature sig(Move(argTypes), retType);
|
||||
Signature sig(OldMove(argTypes), retType);
|
||||
ModuleCompiler::Func *func;
|
||||
if (!CheckFunctionSignature(m, fn, Move(sig), FunctionName(fn), &func))
|
||||
if (!CheckFunctionSignature(m, fn, OldMove(sig), FunctionName(fn), &func))
|
||||
return false;
|
||||
|
||||
if (func->defined())
|
||||
|
@ -5057,10 +5057,10 @@ CheckFuncPtrTable(ModuleCompiler &m, ParseNode *var)
|
|||
return false;
|
||||
|
||||
ModuleCompiler::FuncPtrTable *table;
|
||||
if (!CheckFuncPtrTableAgainstExisting(m, var, var->name(), Move(sig), mask, &table))
|
||||
if (!CheckFuncPtrTableAgainstExisting(m, var, var->name(), OldMove(sig), mask, &table))
|
||||
return false;
|
||||
|
||||
table->initElems(Move(elems));
|
||||
table->initElems(OldMove(elems));
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
|
@ -228,7 +228,7 @@ class AsmJSModule
|
|||
ExportedFunction(mozilla::MoveRef<ExportedFunction> rhs) {
|
||||
name_ = rhs->name_;
|
||||
maybeFieldName_ = rhs->maybeFieldName_;
|
||||
argCoercions_ = mozilla::Move(rhs->argCoercions_);
|
||||
argCoercions_ = mozilla::OldMove(rhs->argCoercions_);
|
||||
pod = rhs->pod;
|
||||
}
|
||||
|
||||
|
@ -288,12 +288,12 @@ class AsmJSModule
|
|||
|
||||
ProfiledBlocksFunction(JSAtom *name, unsigned start, unsigned end,
|
||||
jit::PerfSpewer::BasicBlocksVector &blocksVector)
|
||||
: ProfiledFunction(name, start, end), blocks(mozilla::Move(blocksVector))
|
||||
: ProfiledFunction(name, start, end), blocks(mozilla::OldMove(blocksVector))
|
||||
{ }
|
||||
|
||||
ProfiledBlocksFunction(const ProfiledBlocksFunction ©)
|
||||
: ProfiledFunction(copy.name, copy.startCodeOffset, copy.endCodeOffset),
|
||||
blocks(mozilla::Move(copy.blocks))
|
||||
blocks(mozilla::OldMove(copy.blocks))
|
||||
{ }
|
||||
};
|
||||
#endif
|
||||
|
@ -457,7 +457,7 @@ class AsmJSModule
|
|||
ReturnType returnType)
|
||||
{
|
||||
ExportedFunction func(name, maybeFieldName, argCoercions, returnType);
|
||||
return exports_.append(mozilla::Move(func));
|
||||
return exports_.append(mozilla::OldMove(func));
|
||||
}
|
||||
unsigned numExportedFunctions() const {
|
||||
return exports_.length();
|
||||
|
|
|
@ -25,7 +25,7 @@
|
|||
#include "vm/ObjectImpl-inl.h"
|
||||
|
||||
using mozilla::DebugOnly;
|
||||
using mozilla::Move;
|
||||
using mozilla::OldMove;
|
||||
using mozilla::MoveRef;
|
||||
using mozilla::PodEqual;
|
||||
|
||||
|
@ -439,7 +439,7 @@ FindNotableStrings(ZoneStats &zStats)
|
|||
!zStats.notableStrings.growBy(1))
|
||||
continue;
|
||||
|
||||
zStats.notableStrings.back() = Move(NotableStringInfo(str, info));
|
||||
zStats.notableStrings.back() = OldMove(NotableStringInfo(str, info));
|
||||
|
||||
// We're moving this string from a non-notable to a notable bucket, so
|
||||
// subtract it out of the non-notable tallies.
|
||||
|
|
|
@ -23,7 +23,7 @@
|
|||
|
||||
using namespace js;
|
||||
|
||||
using mozilla::Move;
|
||||
using mozilla::OldMove;
|
||||
using mozilla::MoveRef;
|
||||
|
||||
#ifdef DEBUG
|
||||
|
@ -77,7 +77,7 @@ class HeapReverser : public JSTracer, public JS::CustomAutoRooter
|
|||
* not assignments or copy construction.
|
||||
*/
|
||||
Node(MoveRef<Node> rhs)
|
||||
: kind(rhs->kind), incoming(Move(rhs->incoming)), marked(rhs->marked) { }
|
||||
: kind(rhs->kind), incoming(OldMove(rhs->incoming)), marked(rhs->marked) { }
|
||||
Node &operator=(MoveRef<Node> rhs) {
|
||||
this->~Node();
|
||||
new(this) Node(rhs);
|
||||
|
@ -273,7 +273,7 @@ HeapReverser::traverseEdge(void *cell, JSGCTraceKind kind)
|
|||
*/
|
||||
Node n(kind);
|
||||
uint32_t generation = map.generation();
|
||||
if (!map.add(a, cell, Move(n)) ||
|
||||
if (!map.add(a, cell, OldMove(n)) ||
|
||||
!work.append(Child(cell, kind)))
|
||||
return false;
|
||||
/* If the map has been resized, re-check the pointer. */
|
||||
|
@ -282,7 +282,7 @@ HeapReverser::traverseEdge(void *cell, JSGCTraceKind kind)
|
|||
}
|
||||
|
||||
/* Add this edge to the reversed map. */
|
||||
return a->value.incoming.append(Move(e));
|
||||
return a->value.incoming.append(OldMove(e));
|
||||
}
|
||||
|
||||
bool
|
||||
|
|
85
mfbt/Move.h
85
mfbt/Move.h
|
@ -9,11 +9,21 @@
|
|||
#ifndef mozilla_Move_h
|
||||
#define mozilla_Move_h
|
||||
|
||||
#include "mozilla/TypeTraits.h"
|
||||
|
||||
namespace mozilla {
|
||||
|
||||
/*
|
||||
* "Move" References
|
||||
*
|
||||
* [Once upon a time, C++11 rvalue references were not implemented by all the
|
||||
* compilers we cared about, so we invented mozilla::Move() (now called
|
||||
* OldMove()), which does something similar. We're in the process of
|
||||
* transitioning away from this to pure stl (bug 896100). Until that bug is
|
||||
* completed, this header will provide both mozilla::OldMove() and
|
||||
* mozilla::Move().]
|
||||
*
|
||||
*
|
||||
* Some types can be copied much more efficiently if we know the original's
|
||||
* value need not be preserved --- that is, if we are doing a "move", not a
|
||||
* "copy". For example, if we have:
|
||||
|
@ -48,18 +58,28 @@ namespace mozilla {
|
|||
* efficiently than it can be copied, and provide an implementation of that
|
||||
* move operation.
|
||||
*
|
||||
* The Move(T&) function takes a reference to a T, and returns a MoveRef<T>
|
||||
* referring to the same value; that's 1). A MoveRef<T> is simply a reference
|
||||
* The OldMove(T&) function takes a reference to a T, and returns a MoveRef<T>
|
||||
* referring to the same value; that's (1). A MoveRef<T> is simply a reference
|
||||
* to a T, annotated to say that a copy constructor applied to it may move that
|
||||
* T, instead of copying it. Finally, a constructor that accepts an MoveRef<T>
|
||||
* should perform a more efficient move, instead of a copy, providing 2).
|
||||
* should perform a more efficient move, instead of a copy, providing (2).
|
||||
*
|
||||
* So, where we might define a copy constructor for a class C like this:
|
||||
* The Move(T&) function takes a reference to a T and returns a T&&. It acts
|
||||
* just like std::move(), which is not available on all our platforms.
|
||||
*
|
||||
* In new code, you should use Move(T&) and T&& instead of OldMove(T&) and
|
||||
* MoveRef<T>, where possible.
|
||||
*
|
||||
* Where we might define a copy constructor for a class C like this:
|
||||
*
|
||||
* C(const C& rhs) { ... copy rhs to this ... }
|
||||
*
|
||||
* we would declare a move constructor like this:
|
||||
*
|
||||
* C(C&& rhs) { .. move rhs to this ... }
|
||||
*
|
||||
* or, in the deprecated OldMove style:
|
||||
*
|
||||
* C(MoveRef<C> rhs) { ... move rhs to this ... }
|
||||
*
|
||||
* And where we might perform a copy like this:
|
||||
|
@ -68,7 +88,11 @@ namespace mozilla {
|
|||
*
|
||||
* we would perform a move like this:
|
||||
*
|
||||
* C c2(Move(c1))
|
||||
* C c2(Move(c1));
|
||||
*
|
||||
* or, in the deprecated OldMove style:
|
||||
*
|
||||
* C c2(OldMove(c1));
|
||||
*
|
||||
* Note that MoveRef<T> implicitly converts to T&, so you can pass a MoveRef<T>
|
||||
* to an ordinary copy constructor for a type that doesn't support a special
|
||||
|
@ -82,7 +106,7 @@ namespace mozilla {
|
|||
* which runs this's destructor, and then applies the move constructor to
|
||||
* *this's memory. A typical definition:
|
||||
*
|
||||
* C& operator=(MoveRef<C> rhs) {
|
||||
* C& operator=(C&& rhs) { // or |MoveRef<C> rhs|
|
||||
* this->~C();
|
||||
* new(this) C(rhs);
|
||||
* return *this;
|
||||
|
@ -90,14 +114,14 @@ namespace mozilla {
|
|||
*
|
||||
* With that in place, one can write move assignments like this:
|
||||
*
|
||||
* c2 = Move(c1);
|
||||
* c2 = Move(c1); // or OldMove()
|
||||
*
|
||||
* This destroys c1, moves c1's value to c2, and leaves c1 in an undefined but
|
||||
* destructible state.
|
||||
*
|
||||
* This header file defines MoveRef and Move in the mozilla namespace. It's up
|
||||
* to individual containers to annotate moves as such, by calling Move; and it's
|
||||
* up to individual types to define move constructors.
|
||||
* This header file defines MoveRef, Move, and OldMove in the mozilla namespace.
|
||||
* It's up to individual containers to annotate moves as such, by calling Move
|
||||
* or OldMove; and it's up to individual types to define move constructors.
|
||||
*
|
||||
* One hint: if you're writing a move constructor where the type has members
|
||||
* that should be moved themselves, it's much nicer to write this:
|
||||
|
@ -125,14 +149,14 @@ class MoveRef
|
|||
|
||||
template<typename T>
|
||||
inline MoveRef<T>
|
||||
Move(T& t)
|
||||
OldMove(T& t)
|
||||
{
|
||||
return MoveRef<T>(t);
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
inline MoveRef<T>
|
||||
Move(const T& t)
|
||||
OldMove(const T& t)
|
||||
{
|
||||
// With some versions of gcc, for a class C, there's an (incorrect) ambiguity
|
||||
// between the C(const C&) constructor and the default C(C&&) C++11 move
|
||||
|
@ -151,14 +175,45 @@ Move(const T& t)
|
|||
return MoveRef<T>(const_cast<T&>(t));
|
||||
}
|
||||
|
||||
/**
|
||||
* Identical to std::Move(); this is necessary until our stlport supports
|
||||
* std::move().
|
||||
*/
|
||||
template<typename T>
|
||||
inline typename RemoveReference<T>::Type&&
|
||||
Move(T&& a)
|
||||
{
|
||||
return static_cast<typename RemoveReference<T>::Type&&>(a);
|
||||
}
|
||||
|
||||
/**
|
||||
* These two overloads are identidal to std::Forward(); they are necessary until
|
||||
* our stlport supports std::forward().
|
||||
*/
|
||||
template<typename T>
|
||||
inline T&&
|
||||
Forward(typename RemoveReference<T>::Type& a)
|
||||
{
|
||||
return static_cast<T&&>(a);
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
inline T&&
|
||||
Forward(typename RemoveReference<T>::Type&& t)
|
||||
{
|
||||
static_assert(!IsLvalueReference<T>::value,
|
||||
"misuse of Forward detected! try the other overload");
|
||||
return static_cast<T&&>(t);
|
||||
}
|
||||
|
||||
/** Swap |t| and |u| using move-construction if possible. */
|
||||
template<typename T>
|
||||
inline void
|
||||
Swap(T& t, T& u)
|
||||
{
|
||||
T tmp(Move(t));
|
||||
t = Move(u);
|
||||
u = Move(tmp);
|
||||
T tmp(OldMove(t));
|
||||
t = OldMove(u);
|
||||
u = OldMove(tmp);
|
||||
}
|
||||
|
||||
} // namespace mozilla
|
||||
|
|
|
@ -418,6 +418,16 @@ struct IsConvertible
|
|||
: IntegralConstant<bool, detail::ConvertibleTester<From, To>::value>
|
||||
{};
|
||||
|
||||
/**
|
||||
* Is IsLvalueReference<T> is true if its template param is T& and is false if
|
||||
* its type is T or T&&.
|
||||
*/
|
||||
template<typename T>
|
||||
struct IsLvalueReference : FalseType {};
|
||||
|
||||
template<typename T>
|
||||
struct IsLvalueReference<T&> : TrueType {};
|
||||
|
||||
/* 20.9.7 Transformations between types [meta.trans] */
|
||||
|
||||
/* 20.9.7.1 Const-volatile modifications [meta.trans.cv] */
|
||||
|
@ -478,6 +488,32 @@ struct RemoveCV
|
|||
|
||||
/* 20.9.7.2 Reference modifications [meta.trans.ref] */
|
||||
|
||||
/**
|
||||
* Converts reference types to the underlying types.
|
||||
*
|
||||
* mozilla::RemoveReference<T>::Type is T;
|
||||
* mozilla::RemoveReference<T&>::Type is T;
|
||||
* mozilla::RemoveReference<T&&>::Type is T;
|
||||
*/
|
||||
|
||||
template<typename T>
|
||||
struct RemoveReference
|
||||
{
|
||||
typedef T Type;
|
||||
};
|
||||
|
||||
template<typename T>
|
||||
struct RemoveReference<T&>
|
||||
{
|
||||
typedef T Type;
|
||||
};
|
||||
|
||||
template<typename T>
|
||||
struct RemoveReference<T&&>
|
||||
{
|
||||
typedef T Type;
|
||||
};
|
||||
|
||||
/* 20.9.7.3 Sign modifications [meta.trans.sign] */
|
||||
|
||||
template<bool B, typename T = void>
|
||||
|
|
|
@ -86,7 +86,7 @@ struct VectorImpl
|
|||
template<typename U>
|
||||
static inline void moveConstruct(T* dst, const U* srcbeg, const U* srcend) {
|
||||
for (const U* p = srcbeg; p < srcend; ++p, ++dst)
|
||||
new(dst) T(Move(*p));
|
||||
new(dst) T(OldMove(*p));
|
||||
}
|
||||
|
||||
/*
|
||||
|
@ -115,7 +115,7 @@ struct VectorImpl
|
|||
T* dst = newbuf;
|
||||
T* src = v.beginNoCheck();
|
||||
for (; src < v.endNoCheck(); ++dst, ++src)
|
||||
new(dst) T(Move(*src));
|
||||
new(dst) T(OldMove(*src));
|
||||
VectorImpl::destroy(v.beginNoCheck(), v.endNoCheck());
|
||||
v.free_(v.mBegin);
|
||||
v.mBegin = newbuf;
|
||||
|
|
|
@ -91,12 +91,19 @@ class nsAutoPtr
|
|||
{
|
||||
}
|
||||
|
||||
// This constructor shouldn't exist; we should just use the &&
|
||||
// constructor.
|
||||
nsAutoPtr( nsAutoPtr<T>& aSmartPtr )
|
||||
: mRawPtr( aSmartPtr.forget() )
|
||||
// Construct by transferring ownership from another smart pointer.
|
||||
{
|
||||
}
|
||||
|
||||
nsAutoPtr( nsAutoPtr<T>&& aSmartPtr )
|
||||
: mRawPtr( aSmartPtr.forget() )
|
||||
// Construct by transferring ownership from another smart pointer.
|
||||
{
|
||||
}
|
||||
|
||||
// Assignment operators
|
||||
|
||||
|
|
|
@ -7,6 +7,7 @@
|
|||
#define nsBaseHashtable_h__
|
||||
|
||||
#include "mozilla/MemoryReporting.h"
|
||||
#include "mozilla/Move.h"
|
||||
#include "nsTHashtable.h"
|
||||
#include "prlock.h"
|
||||
#include "nsDebug.h"
|
||||
|
@ -31,7 +32,7 @@ private:
|
|||
typedef typename KeyClass::KeyTypePointer KeyTypePointer;
|
||||
|
||||
nsBaseHashtableET(KeyTypePointer aKey);
|
||||
nsBaseHashtableET(nsBaseHashtableET<KeyClass,DataType>& toCopy);
|
||||
nsBaseHashtableET(nsBaseHashtableET<KeyClass,DataType>&& toMove);
|
||||
~nsBaseHashtableET();
|
||||
};
|
||||
|
||||
|
@ -411,9 +412,9 @@ nsBaseHashtableET<KeyClass,DataType>::nsBaseHashtableET(KeyTypePointer aKey) :
|
|||
|
||||
template<class KeyClass,class DataType>
|
||||
nsBaseHashtableET<KeyClass,DataType>::nsBaseHashtableET
|
||||
(nsBaseHashtableET<KeyClass,DataType>& toCopy) :
|
||||
KeyClass(toCopy),
|
||||
mData(toCopy.mData)
|
||||
(nsBaseHashtableET<KeyClass,DataType>&& toMove) :
|
||||
KeyClass(mozilla::Move(toMove)),
|
||||
mData(mozilla::Move(toMove.mData))
|
||||
{ }
|
||||
|
||||
template<class KeyClass,class DataType>
|
||||
|
|
|
@ -9,11 +9,13 @@
|
|||
#include "nscore.h"
|
||||
#include "pldhash.h"
|
||||
#include "nsDebug.h"
|
||||
#include <new>
|
||||
#include "mozilla/MemoryChecking.h"
|
||||
#include "mozilla/MemoryReporting.h"
|
||||
#include "mozilla/Move.h"
|
||||
#include "mozilla/fallible.h"
|
||||
|
||||
#include <new>
|
||||
|
||||
// helper function for nsTHashtable::Clear()
|
||||
NS_COM_GLUE PLDHashOperator
|
||||
PL_DHashStubEnumRemove(PLDHashTable *table,
|
||||
|
@ -46,10 +48,10 @@ PL_DHashStubEnumRemove(PLDHashTable *table,
|
|||
*
|
||||
* EntryType(KeyTypePointer aKey);
|
||||
*
|
||||
* // A copy or move constructor must be defined, even if AllowMemMove() ==
|
||||
* // true, otherwise you will cause link errors.
|
||||
* EntryType(const EntryType& aEnt); // Either this...
|
||||
* EntryType(MoveRef<EntryType> aEnt); // ...or this
|
||||
* // A copy or C++11 Move constructor must be defined, even if
|
||||
* // AllowMemMove() == true, otherwise you will cause link errors.
|
||||
* EntryType(const EntryType& aEnt); // Either this...
|
||||
* EntryType(EntryType&& aEnt); // ...or this
|
||||
*
|
||||
* // the destructor must be defined... or you will cause link errors!
|
||||
* ~EntryType();
|
||||
|
@ -90,7 +92,7 @@ public:
|
|||
*/
|
||||
~nsTHashtable();
|
||||
|
||||
nsTHashtable(mozilla::MoveRef<nsTHashtable<EntryType> > aOther);
|
||||
nsTHashtable(nsTHashtable<EntryType>&& aOther);
|
||||
|
||||
/**
|
||||
* Initialize the table. This function must be called before any other
|
||||
|
@ -378,17 +380,23 @@ private:
|
|||
template<class EntryType>
|
||||
nsTHashtable<EntryType>::nsTHashtable()
|
||||
{
|
||||
// entrySize is our "I'm initialized" indicator
|
||||
// mTable.entrySize == 0 means we're not yet initialized. In Init(), we set
|
||||
// mTable.entrySize == sizeof(EntryType).
|
||||
mTable.entrySize = 0;
|
||||
}
|
||||
|
||||
template<class EntryType>
|
||||
nsTHashtable<EntryType>::nsTHashtable(
|
||||
mozilla::MoveRef<nsTHashtable<EntryType> > aOther)
|
||||
: mTable(aOther->mTable)
|
||||
nsTHashtable<EntryType>&& aOther)
|
||||
: mTable(mozilla::Move(aOther.mTable))
|
||||
{
|
||||
aOther->mTable = PLDHashTable();
|
||||
aOther->mTable.entrySize = 0;
|
||||
// aOther shouldn't touch mTable after this, because we've stolen the table's
|
||||
// pointers but not overwitten them.
|
||||
MOZ_MAKE_MEM_UNDEFINED(aOther.mTable, sizeof(aOther.mTable));
|
||||
|
||||
// Indicate that aOther is not initialized. This will make its destructor a
|
||||
// nop, which is what we want.
|
||||
aOther.mTable.entrySize = 0;
|
||||
}
|
||||
|
||||
template<class EntryType>
|
||||
|
@ -461,12 +469,10 @@ nsTHashtable<EntryType>::s_CopyEntry(PLDHashTable *table,
|
|||
const PLDHashEntryHdr *from,
|
||||
PLDHashEntryHdr *to)
|
||||
{
|
||||
using mozilla::Move;
|
||||
|
||||
EntryType* fromEntry =
|
||||
const_cast<EntryType*>(reinterpret_cast<const EntryType*>(from));
|
||||
|
||||
new(to) EntryType(Move(*fromEntry));
|
||||
new(to) EntryType(mozilla::Move(*fromEntry));
|
||||
|
||||
fromEntry->~EntryType();
|
||||
}
|
||||
|
|
Загрузка…
Ссылка в новой задаче