Bug 1302401 - With move semantics added to the language and the standard library updated with move constructors added for many types it is now interesting to take an argument directly by value, instead of by const-reference, and then copy. This check allows the compiler to take care of choosing the best way to construct the copy.
MozReview-Commit-ID: HRs94SYGK5Z
--- a/js/src/ds/OrderedHashTable.h
+++ b/js/src/ds/OrderedHashTable.h
@@ -30,16 +30,18 @@
* See the comment about "Hash policy" in HashTable.h for general features that
* hash policy classes must provide. Hash policies for OrderedHashMaps and Sets
* must additionally provide a distinguished "empty" key value and the
* following static member functions:
* bool isEmpty(const Key&);
* void makeEmpty(Key*);
*/
+#include <utility>
+
#include "mozilla/Move.h"
using mozilla::Forward;
using mozilla::Move;
namespace js {
namespace detail {
@@ -699,17 +701,17 @@ class OrderedHashMap
MOZ_ASSERT(this != &rhs, "self-move assignment is prohibited");
const_cast<Key&>(key) = Move(rhs.key);
value = Move(rhs.value);
}
public:
Entry() : key(), value() {}
template <typename V>
- Entry(const Key& k, V&& v) : key(k), value(Forward<V>(v)) {}
+ Entry(Key k, V&& v) : key(std::move(k)), value(Forward<V>(v)) {}
Entry(Entry&& rhs) : key(Move(rhs.key)), value(Move(rhs.value)) {}
const Key key;
Value value;
static size_t offsetOfKey() {
return offsetof(Entry, key);
}
--- a/js/src/frontend/ParseNode.h
+++ b/js/src/frontend/ParseNode.h
@@ -2,16 +2,18 @@
* vim: set ts=8 sts=4 et sw=4 tw=99:
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#ifndef frontend_ParseNode_h
#define frontend_ParseNode_h
+#include <utility>
+
#include "mozilla/Attributes.h"
#include "builtin/ModuleObject.h"
#include "frontend/TokenStream.h"
namespace js {
namespace frontend {
@@ -455,22 +457,22 @@ class ParseNode
pn_parens(false),
pn_pos(0, 0),
pn_next(nullptr)
{
MOZ_ASSERT(kind < PNK_LIMIT);
memset(&pn_u, 0, sizeof pn_u);
}
- ParseNode(ParseNodeKind kind, JSOp op, ParseNodeArity arity, const TokenPos& pos)
+ ParseNode(ParseNodeKind kind, JSOp op, ParseNodeArity arity, TokenPos pos)
: pn_type(kind),
pn_op(op),
pn_arity(arity),
pn_parens(false),
- pn_pos(pos),
+ pn_pos(std::move(pos)),
pn_next(nullptr)
{
MOZ_ASSERT(kind < PNK_LIMIT);
memset(&pn_u, 0, sizeof pn_u);
}
JSOp getOp() const { return JSOp(pn_op); }
void setOp(JSOp op) { pn_op = op; }
--- a/js/src/gc/Barrier.h
+++ b/js/src/gc/Barrier.h
@@ -2,16 +2,18 @@
* vim: set ts=8 sts=4 et sw=4 tw=99:
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#ifndef gc_Barrier_h
#define gc_Barrier_h
+#include <utility>
+
#include "NamespaceImports.h"
#include "gc/Heap.h"
#include "gc/StoreBuffer.h"
#include "js/HeapAPI.h"
#include "js/Id.h"
#include "js/RootingAPI.h"
#include "js/Value.h"
@@ -509,17 +511,17 @@ class HeapPtr : public WriteBarrieredBas
}
/*
* For HeapPtr, move semantics are equivalent to copy semantics. In
* C++, a copy constructor taking const-ref is the way to get a single
* function that will be used for both lvalue and rvalue copies, so we can
* simply omit the rvalue variant.
*/
- MOZ_IMPLICIT HeapPtr(const HeapPtr<T>& v) : WriteBarrieredBase<T>(v) {
+ MOZ_IMPLICIT HeapPtr(HeapPtr<T> v) : WriteBarrieredBase<T>(std::move(v)) {
this->post(JS::GCPolicy<T>::initial(), this->value);
}
~HeapPtr() {
this->pre();
this->post(this->value, JS::GCPolicy<T>::initial());
}
--- a/js/src/gc/GCRuntime.h
+++ b/js/src/gc/GCRuntime.h
@@ -2,16 +2,18 @@
* vim: set ts=8 sts=4 et sw=4 tw=99:
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#ifndef gc_GCRuntime_h
#define gc_GCRuntime_h
+#include <utility>
+
#include "mozilla/Atomics.h"
#include "mozilla/EnumSet.h"
#include "jsfriendapi.h"
#include "jsgc.h"
#include "gc/Heap.h"
#include "gc/Nursery.h"
@@ -556,18 +558,18 @@ using CallbackVector = Vector<Callback<F
template <typename T, typename Iter0, typename Iter1>
class ChainedIter
{
Iter0 iter0_;
Iter1 iter1_;
public:
- ChainedIter(const Iter0& iter0, const Iter1& iter1)
- : iter0_(iter0), iter1_(iter1)
+ ChainedIter(Iter0 iter0, Iter1 iter1)
+ : iter0_(std::move(iter0)), iter1_(std::move(iter1))
{}
bool done() const { return iter0_.done() && iter1_.done(); }
void next() {
MOZ_ASSERT(!done());
if (!iter0_.done()) {
iter0_.next();
} else {
--- a/js/src/jit/Disassembler.h
+++ b/js/src/jit/Disassembler.h
@@ -2,16 +2,18 @@
* vim: set ts=8 sts=4 et sw=4 tw=99:
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#ifndef jit_Disassembler_h
#define jit_Disassembler_h
+#include <utility>
+
#include "jit/MacroAssembler.h"
#include "jit/Registers.h"
namespace js {
namespace jit {
namespace Disassembler {
@@ -215,21 +217,21 @@ class HeapAccess {
public:
HeapAccess()
: kind_(Unknown),
size_(0)
{
MOZ_ASSERT(*this == *this);
}
- HeapAccess(Kind kind, size_t size, const ComplexAddress& address, const OtherOperand& otherOperand)
+ HeapAccess(Kind kind, size_t size, ComplexAddress address, OtherOperand otherOperand)
: kind_(kind),
size_(size),
- address_(address),
- otherOperand_(otherOperand)
+ address_(std::move(address)),
+ otherOperand_(std::move(otherOperand))
{
MOZ_ASSERT(kind != Unknown);
MOZ_ASSERT_IF(kind == LoadSext32, otherOperand.kind() != OtherOperand::FPR);
MOZ_ASSERT_IF(kind == Load || kind == LoadSext32, otherOperand.kind() != OtherOperand::Imm);
MOZ_ASSERT(*this == *this);
}
Kind kind() const {
--- a/js/src/jit/LIR.h
+++ b/js/src/jit/LIR.h
@@ -5,16 +5,18 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#ifndef jit_LIR_h
#define jit_LIR_h
// This file declares the core data structures for LIR: storage allocations for
// inputs and outputs, as well as the interface instructions must conform to.
+#include <utility>
+
#include "mozilla/Array.h"
#include "jit/Bailouts.h"
#include "jit/FixedList.h"
#include "jit/InlineList.h"
#include "jit/JitAllocPolicy.h"
#include "jit/LOpcodes.h"
#include "jit/MIR.h"
@@ -494,24 +496,24 @@ class LDefinition
LDefinition(uint32_t index, Type type, Policy policy = REGISTER) {
set(index, type, policy);
}
explicit LDefinition(Type type, Policy policy = REGISTER) {
set(0, type, policy);
}
- LDefinition(Type type, const LAllocation& a)
- : output_(a)
+ LDefinition(Type type, LAllocation a)
+ : output_(std::move(a))
{
set(0, type, FIXED);
}
- LDefinition(uint32_t index, Type type, const LAllocation& a)
- : output_(a)
+ LDefinition(uint32_t index, Type type, LAllocation a)
+ : output_(std::move(a))
{
set(index, type, FIXED);
}
LDefinition() : bits_(0)
{
MOZ_ASSERT(isBogusTemp());
}
--- a/js/src/jit/MIR.h
+++ b/js/src/jit/MIR.h
@@ -7,16 +7,18 @@
/*
* Everything needed to build actual MIR instructions: the actual opcodes and
* instructions, the instruction interface, and use chains.
*/
#ifndef jit_MIR_h
#define jit_MIR_h
+#include <utility>
+
#include "mozilla/Array.h"
#include "mozilla/Attributes.h"
#include "mozilla/MacroForEach.h"
#include "builtin/SIMD.h"
#include "jit/AtomicOp.h"
#include "jit/BaselineIC.h"
#include "jit/FixedList.h"
@@ -1687,17 +1689,17 @@ class MSimdSplat
// A constant SIMD value.
class MSimdConstant
: public MNullaryInstruction
{
SimdConstant value_;
protected:
- MSimdConstant(const SimdConstant& v, MIRType type) : value_(v) {
+ MSimdConstant(SimdConstant v, MIRType type) : value_(std::move(v)) {
MOZ_ASSERT(IsSimdType(type));
setMovable();
setResultType(type);
}
public:
INSTRUCTION_HEADER(SimdConstant)
TRIVIAL_NEW_WRAPPERS
@@ -13327,19 +13329,19 @@ class MWasmMemoryAccess
void clearOffset() { offset_ = 0; }
};
class MWasmLoad
: public MUnaryInstruction,
public MWasmMemoryAccess,
public NoTypePolicy::Data
{
- MWasmLoad(MDefinition* base, const MWasmMemoryAccess& access, MIRType resultType)
+ MWasmLoad(MDefinition* base, MWasmMemoryAccess access, MIRType resultType)
: MUnaryInstruction(base),
- MWasmMemoryAccess(access)
+ MWasmMemoryAccess(std::move(access))
{
setGuard();
setResultType(resultType);
}
public:
INSTRUCTION_HEADER(WasmLoad)
TRIVIAL_NEW_WRAPPERS
@@ -13354,19 +13356,19 @@ class MWasmLoad
}
};
class MWasmStore
: public MBinaryInstruction,
public MWasmMemoryAccess,
public NoTypePolicy::Data
{
- MWasmStore(MDefinition* base, const MWasmMemoryAccess& access, MDefinition* value)
+ MWasmStore(MDefinition* base, MWasmMemoryAccess access, MDefinition* value)
: MBinaryInstruction(base, value),
- MWasmMemoryAccess(access)
+ MWasmMemoryAccess(std::move(access))
{
setGuard();
}
public:
INSTRUCTION_HEADER(WasmStore)
TRIVIAL_NEW_WRAPPERS
NAMED_OPERANDS((0, base), (1, value))
@@ -13451,20 +13453,20 @@ class MAsmJSStoreHeap
}
};
class MAsmJSCompareExchangeHeap
: public MQuaternaryInstruction,
public MWasmMemoryAccess,
public NoTypePolicy::Data
{
- MAsmJSCompareExchangeHeap(MDefinition* base, const MWasmMemoryAccess& access,
+ MAsmJSCompareExchangeHeap(MDefinition* base, MWasmMemoryAccess access,
MDefinition* oldv, MDefinition* newv, MDefinition* tls)
: MQuaternaryInstruction(base, oldv, newv, tls),
- MWasmMemoryAccess(access)
+ MWasmMemoryAccess(std::move(access))
{
setGuard(); // Not removable
setResultType(MIRType::Int32);
}
public:
INSTRUCTION_HEADER(AsmJSCompareExchangeHeap)
TRIVIAL_NEW_WRAPPERS
@@ -13479,20 +13481,20 @@ class MAsmJSCompareExchangeHeap
}
};
class MAsmJSAtomicExchangeHeap
: public MTernaryInstruction,
public MWasmMemoryAccess,
public NoTypePolicy::Data
{
- MAsmJSAtomicExchangeHeap(MDefinition* base, const MWasmMemoryAccess& access,
+ MAsmJSAtomicExchangeHeap(MDefinition* base, MWasmMemoryAccess access,
MDefinition* value, MDefinition* tls)
: MTernaryInstruction(base, value, tls),
- MWasmMemoryAccess(access)
+ MWasmMemoryAccess(std::move(access))
{
setGuard(); // Not removable
setResultType(MIRType::Int32);
}
public:
INSTRUCTION_HEADER(AsmJSAtomicExchangeHeap)
TRIVIAL_NEW_WRAPPERS
@@ -13508,20 +13510,20 @@ class MAsmJSAtomicExchangeHeap
class MAsmJSAtomicBinopHeap
: public MTernaryInstruction,
public MWasmMemoryAccess,
public NoTypePolicy::Data
{
AtomicOp op_;
- MAsmJSAtomicBinopHeap(AtomicOp op, MDefinition* base, const MWasmMemoryAccess& access,
+ MAsmJSAtomicBinopHeap(AtomicOp op, MDefinition* base, MWasmMemoryAccess access,
MDefinition* v, MDefinition* tls)
: MTernaryInstruction(base, v, tls),
- MWasmMemoryAccess(access),
+ MWasmMemoryAccess(std::move(access)),
op_(op)
{
setGuard(); // Not removable
setResultType(MIRType::Int32);
}
public:
INSTRUCTION_HEADER(AsmJSAtomicBinopHeap)
@@ -13663,20 +13665,20 @@ class MWasmCall final
{
wasm::CallSiteDesc desc_;
wasm::CalleeDesc callee_;
FixedList<AnyRegister> argRegs_;
uint32_t spIncrement_;
uint32_t tlsStackOffset_;
ABIArg instanceArg_;
- MWasmCall(const wasm::CallSiteDesc& desc, const wasm::CalleeDesc& callee, uint32_t spIncrement,
+ MWasmCall(wasm::CallSiteDesc desc, wasm::CalleeDesc callee, uint32_t spIncrement,
uint32_t tlsStackOffset)
- : desc_(desc),
- callee_(callee),
+ : desc_(std::move(desc)),
+ callee_(std::move(callee)),
spIncrement_(spIncrement),
tlsStackOffset_(tlsStackOffset)
{ }
public:
INSTRUCTION_HEADER(WasmCall)
struct Arg {
--- a/js/src/jit/RegisterSets.h
+++ b/js/src/jit/RegisterSets.h
@@ -2,16 +2,18 @@
* vim: set ts=8 sts=4 et sw=4 tw=99:
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#ifndef jit_RegisterSets_h
#define jit_RegisterSets_h
+#include <utility>
+
#include "mozilla/MathAlgorithms.h"
#include "jit/JitAllocPolicy.h"
#include "jit/Registers.h"
namespace js {
namespace jit {
@@ -593,17 +595,17 @@ class AllocatableSetAccessors<RegisterSe
typedef char SetType;
protected:
RegisterSet set_;
public:
AllocatableSetAccessors() : set_() {}
explicit constexpr AllocatableSetAccessors(SetType) = delete;
- explicit constexpr AllocatableSetAccessors(RegisterSet set) : set_(set) {}
+ explicit constexpr AllocatableSetAccessors(RegisterSet set) : set_(std::move(set)) {}
bool has(Register reg) const {
return set_.gprs().hasAllocatable(reg);
}
bool has(FloatRegister reg) const {
return set_.fpus().hasAllocatable(reg);
}
@@ -675,17 +677,17 @@ class LiveSetAccessors<RegisterSet>
typedef char SetType;
protected:
RegisterSet set_;
public:
LiveSetAccessors() : set_() {}
explicit constexpr LiveSetAccessors(SetType) = delete;
- explicit constexpr LiveSetAccessors(RegisterSet set) : set_(set) {}
+ explicit constexpr LiveSetAccessors(RegisterSet set) : set_(std::move(set)) {}
bool has(Register reg) const {
return set_.gprs().hasRegisterIndex(reg);
}
bool has(FloatRegister reg) const {
return set_.fpus().hasRegisterIndex(reg);
}
--- a/js/src/jit/shared/Assembler-shared.h
+++ b/js/src/jit/shared/Assembler-shared.h
@@ -6,16 +6,18 @@
#ifndef jit_shared_Assembler_shared_h
#define jit_shared_Assembler_shared_h
#include "mozilla/PodOperations.h"
#include <limits.h>
+#include <utility>
+
#include "asmjs/WasmTypes.h"
#include "jit/JitAllocPolicy.h"
#include "jit/Label.h"
#include "jit/Registers.h"
#include "jit/RegisterSets.h"
#include "vm/HelperThreads.h"
#if defined(JS_CODEGEN_ARM) || defined(JS_CODEGEN_ARM64) || \
@@ -461,22 +463,22 @@ class CodeLabel
// The source label (relative) in the code to where the destination should
// get patched to.
CodeOffset target_;
public:
CodeLabel()
{ }
- explicit CodeLabel(const CodeOffset& patchAt)
- : patchAt_(patchAt)
+ explicit CodeLabel(CodeOffset patchAt)
+ : patchAt_(std::move(patchAt))
{ }
- CodeLabel(const CodeOffset& patchAt, const CodeOffset& target)
- : patchAt_(patchAt),
- target_(target)
+ CodeLabel(CodeOffset patchAt, CodeOffset target)
+ : patchAt_(std::move(patchAt)),
+ target_(std::move(target))
{ }
CodeOffset* patchAt() {
return &patchAt_;
}
CodeOffset* target() {
return &target_;
}
void offsetBy(size_t delta) {
--- a/js/src/jit/x86-shared/MacroAssembler-x86-shared.h
+++ b/js/src/jit/x86-shared/MacroAssembler-x86-shared.h
@@ -2,16 +2,18 @@
* vim: set ts=8 sts=4 et sw=4 tw=99:
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#ifndef jit_x86_shared_MacroAssembler_x86_shared_h
#define jit_x86_shared_MacroAssembler_x86_shared_h
+#include <utility>
+
#include "mozilla/Casting.h"
#if defined(JS_CODEGEN_X86)
# include "jit/x86/Assembler-x86.h"
#elif defined(JS_CODEGEN_X64)
# include "jit/x64/Assembler-x64.h"
#endif
@@ -53,17 +55,17 @@ class MacroAssemblerX86Shared : public A
// knows what to use instead of copying these data structures.
template<class T>
struct Constant {
typedef T Pod;
T value;
UsesVector uses;
- explicit Constant(const T& value) : value(value) {}
+ explicit Constant(T value) : value(std::move(value)) {}
Constant(Constant<T>&& other) : value(other.value), uses(mozilla::Move(other.uses)) {}
explicit Constant(const Constant<T>&) = delete;
};
// Containers use SystemAllocPolicy since asm.js releases memory after each
// function is compiled, and these need to live until after all functions
// are compiled.
using Double = Constant<double>;
--- a/js/src/jsapi.h
+++ b/js/src/jsapi.h
@@ -18,16 +18,18 @@
#include "mozilla/RefPtr.h"
#include "mozilla/Variant.h"
#include <stdarg.h>
#include <stddef.h>
#include <stdint.h>
#include <stdio.h>
+#include <utility>
+
#include "jsalloc.h"
#include "jspubtd.h"
#include "js/CallArgs.h"
#include "js/CharacterEncoding.h"
#include "js/Class.h"
#include "js/GCVector.h"
#include "js/HashTable.h"
@@ -2333,20 +2335,20 @@ class JS_PUBLIC_API(CompartmentBehaviors
class JS_PUBLIC_API(CompartmentOptions)
{
public:
explicit CompartmentOptions()
: creationOptions_(),
behaviors_()
{}
- CompartmentOptions(const CompartmentCreationOptions& compartmentCreation,
- const CompartmentBehaviors& compartmentBehaviors)
- : creationOptions_(compartmentCreation),
- behaviors_(compartmentBehaviors)
+ CompartmentOptions(CompartmentCreationOptions compartmentCreation,
+ CompartmentBehaviors compartmentBehaviors)
+ : creationOptions_(std::move(compartmentCreation)),
+ behaviors_(std::move(compartmentBehaviors))
{}
// CompartmentCreationOptions specify fundamental compartment
// characteristics that must be specified when the compartment is created,
// that can't be changed after the compartment is created.
CompartmentCreationOptions& creationOptions() {
return creationOptions_;
}