зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1698127 - wasm: Use range-based for loops. r=lth
clang static-analysis prefers to use range-based for loops whenever it is possible. Some of the replacements are obvious improvements, while others are a bit murky. Open to discussion on whether these all make sense. Differential Revision: https://phabricator.services.mozilla.com/D108204
This commit is contained in:
Родитель
a071eeb422
Коммит
4466a7b456
|
@ -3356,8 +3356,7 @@ class BaseCompiler final : public BaseCompilerInterface {
|
|||
}
|
||||
|
||||
[[nodiscard]] bool generateOutOfLineCode() {
|
||||
for (uint32_t i = 0; i < outOfLine_.length(); i++) {
|
||||
OutOfLineCode* ool = outOfLine_[i];
|
||||
for (auto ool : outOfLine_) {
|
||||
ool->bind(&fr, &masm);
|
||||
ool->generate(&masm);
|
||||
}
|
||||
|
@ -5443,8 +5442,7 @@ class BaseCompiler final : public BaseCompilerInterface {
|
|||
// Call this between opcodes.
|
||||
void performRegisterLeakCheck() {
|
||||
BaseRegAlloc::LeakCheck check(ra);
|
||||
for (size_t i = 0; i < stk_.length(); i++) {
|
||||
Stk& item = stk_[i];
|
||||
for (auto& item : stk_) {
|
||||
switch (item.kind_) {
|
||||
case Stk::RegisterI32:
|
||||
check.addKnownI32(item.i32reg());
|
||||
|
@ -6291,10 +6289,10 @@ class BaseCompiler final : public BaseCompilerInterface {
|
|||
#endif
|
||||
masm.bind(theTable);
|
||||
|
||||
for (uint32_t i = 0; i < labels.length(); i++) {
|
||||
for (const auto& label : labels) {
|
||||
CodeLabel cl;
|
||||
masm.writeCodePointer(&cl);
|
||||
cl.target()->bind(labels[i].offset());
|
||||
cl.target()->bind(label.offset());
|
||||
masm.addCodeLabel(cl);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1151,10 +1151,9 @@ const wasm::WasmTryNote* CodeTier::lookupWasmTryNote(const void* pc) const {
|
|||
|
||||
// We find the first hit (there may be multiple) to obtain the innermost
|
||||
// handler, which is why we cannot binary search here.
|
||||
for (size_t i = 0; i < tryNotes.length(); i++) {
|
||||
const WasmTryNote& tn = tryNotes[i];
|
||||
if (target >= tn.begin && target < tn.end) {
|
||||
return &tryNotes[i];
|
||||
for (const auto& tryNote : tryNotes) {
|
||||
if (target >= tryNote.begin && target < tryNote.end) {
|
||||
return &tryNote;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -184,9 +184,9 @@ class StackMaps {
|
|||
public:
|
||||
StackMaps() : sorted_(false) {}
|
||||
~StackMaps() {
|
||||
for (size_t i = 0; i < mapping_.length(); i++) {
|
||||
mapping_[i].map->destroy();
|
||||
mapping_[i].map = nullptr;
|
||||
for (auto& maplet : mapping_) {
|
||||
maplet.map->destroy();
|
||||
maplet.map = nullptr;
|
||||
}
|
||||
}
|
||||
[[nodiscard]] bool add(uint8_t* nextInsnAddr, StackMap* map) {
|
||||
|
@ -197,9 +197,9 @@ class StackMaps {
|
|||
return add(maplet.nextInsnAddr, maplet.map);
|
||||
}
|
||||
void clear() {
|
||||
for (size_t i = 0; i < mapping_.length(); i++) {
|
||||
mapping_[i].nextInsnAddr = nullptr;
|
||||
mapping_[i].map = nullptr;
|
||||
for (auto& maplet : mapping_) {
|
||||
maplet.nextInsnAddr = nullptr;
|
||||
maplet.map = nullptr;
|
||||
}
|
||||
mapping_.clear();
|
||||
}
|
||||
|
@ -213,7 +213,7 @@ class StackMaps {
|
|||
return m;
|
||||
}
|
||||
void offsetBy(uintptr_t delta) {
|
||||
for (size_t i = 0; i < mapping_.length(); i++) mapping_[i].offsetBy(delta);
|
||||
for (auto& maplet : mapping_) maplet.offsetBy(delta);
|
||||
}
|
||||
void sort() {
|
||||
MOZ_ASSERT(!sorted_);
|
||||
|
|
|
@ -1381,9 +1381,7 @@ bool Instance::init(JSContext* cx, const JSFunctionVector& funcImports,
|
|||
ExclusiveData<FuncTypeIdSet>::Guard lockedFuncTypeIdSet =
|
||||
funcTypeIdSet.lock();
|
||||
|
||||
for (uint32_t typeIndex = 0; typeIndex < metadata().types.length();
|
||||
typeIndex++) {
|
||||
const TypeDefWithId& typeDef = metadata().types[typeIndex];
|
||||
for (const TypeDefWithId& typeDef : metadata().types) {
|
||||
switch (typeDef.kind()) {
|
||||
case TypeDefKind::Func: {
|
||||
const FuncType& funcType = typeDef.funcType();
|
||||
|
@ -2145,8 +2143,8 @@ JSString* Instance::createDisplayURL(JSContext* cx) {
|
|||
}
|
||||
|
||||
const ModuleHash& hash = metadata().debugHash;
|
||||
for (size_t i = 0; i < sizeof(ModuleHash); i++) {
|
||||
char digit1 = hash[i] / 16, digit2 = hash[i] % 16;
|
||||
for (unsigned char byte : hash) {
|
||||
char digit1 = byte / 16, digit2 = byte % 16;
|
||||
if (!result.append(
|
||||
(char)(digit1 < 10 ? digit1 + '0' : digit1 + 'a' - 10))) {
|
||||
return nullptr;
|
||||
|
|
|
@ -3694,8 +3694,8 @@ WasmExceptionObject* WasmExceptionObject::create(JSContext* cx,
|
|||
MemoryUse::WasmExceptionTag);
|
||||
|
||||
wasm::ValTypeVector* newValueTypes = js_new<ValTypeVector>();
|
||||
for (uint32_t i = 0; i < type.length(); i++) {
|
||||
if (!newValueTypes->append(type[i])) {
|
||||
for (auto t : type) {
|
||||
if (!newValueTypes->append(t)) {
|
||||
return nullptr;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -3146,7 +3146,7 @@ inline bool OpIter<Policy>::readVectorShuffle(Value* v1, Value* v2,
|
|||
V128* selectMask) {
|
||||
MOZ_ASSERT(Classify(op_) == OpKind::VectorShuffle);
|
||||
|
||||
for (unsigned i = 0; i < 16; i++) {
|
||||
for (unsigned char& byte : selectMask->bytes) {
|
||||
uint8_t tmp;
|
||||
if (!readFixedU8(&tmp)) {
|
||||
return fail("unable to read shuffle index");
|
||||
|
@ -3154,7 +3154,7 @@ inline bool OpIter<Policy>::readVectorShuffle(Value* v1, Value* v2,
|
|||
if (tmp > 31) {
|
||||
return fail("shuffle index out of range");
|
||||
}
|
||||
selectMask->bytes[i] = tmp;
|
||||
byte = tmp;
|
||||
}
|
||||
|
||||
if (!popWithType(ValType::V128, v2)) {
|
||||
|
@ -3174,8 +3174,8 @@ template <typename Policy>
|
|||
inline bool OpIter<Policy>::readV128Const(V128* value) {
|
||||
MOZ_ASSERT(Classify(op_) == OpKind::V128);
|
||||
|
||||
for (unsigned i = 0; i < 16; i++) {
|
||||
if (!readFixedU8(&value->bytes[i])) {
|
||||
for (unsigned char& byte : value->bytes) {
|
||||
if (!readFixedU8(&byte)) {
|
||||
return fail("unable to read V128 constant");
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2215,8 +2215,8 @@ static bool DecodeMemoryLimits(Decoder& d, ModuleEnvironment* env) {
|
|||
|
||||
#ifdef ENABLE_WASM_EXCEPTIONS
|
||||
static bool EventIsJSCompatible(Decoder& d, const ValTypeVector& type) {
|
||||
for (uint32_t i = 0; i < type.length(); i++) {
|
||||
if (type[i].isTypeIndex()) {
|
||||
for (auto t : type) {
|
||||
if (t.isTypeIndex()) {
|
||||
return d.fail("cannot expose indexed reference type");
|
||||
}
|
||||
}
|
||||
|
|
Загрузка…
Ссылка в новой задаче