Bug 1302401 - reduce indentation where possible by removing useless else draft
authorSylvestre Ledru <sylvestre@debian.org>
Tue, 13 Sep 2016 15:03:50 +0200
changeset 413623 d4fdfbe4c4a55919eaa5049c375917ae7a0d4424
parent 413622 fcc3acbd90e620b2e179d2dfc9244a7b94410837
child 413624 30fe3411d82421b4a8a3970222978c2967e89dcd
push id29456
push usersledru@mozilla.com
push dateWed, 14 Sep 2016 14:17:25 +0000
bugs1302401
milestone51.0a1
Bug 1302401 - reduce indentation where possible by removing useless else MozReview-Commit-ID: JC32UIMHjj3
js/public/Value.h
js/src/builtin/TypedObject.h
js/src/ctypes/CTypes.cpp
js/src/ds/SplayTree.h
js/src/gc/Zone.h
js/src/irregexp/RegExpEngine.h
js/src/irregexp/RegExpParser.h
js/src/jit/MoveResolver.h
js/src/jsarray.cpp
js/src/perf/pm_linux.cpp
js/src/vm/Shape-inl.h
js/src/vm/TraceLogging.cpp
js/src/vm/TypeInference-inl.h
js/xpconnect/wrappers/XrayWrapper.cpp
--- a/js/public/Value.h
+++ b/js/public/Value.h
@@ -1102,20 +1102,20 @@ class Value
     void setMagicUint32(uint32_t payload) {
         data = MAGIC_UINT32_TO_JSVAL_IMPL(payload);
     }
 
     bool setNumber(uint32_t ui) {
         if (ui > JSVAL_INT_MAX) {
             setDouble((double)ui);
             return false;
-        } else {
-            setInt32((int32_t)ui);
-            return true;
         }
+        setInt32((int32_t)ui);
+        return true;
+
     }
 
     bool setNumber(double d) {
         int32_t i;
         if (mozilla::NumberIsInt32(d, &i)) {
             setInt32(i);
             return true;
         }
@@ -1855,20 +1855,20 @@ class HeapBase<JS::Value> : public Value
     void setSymbol(JS::Symbol* sym) { setBarriered(JS::SymbolValue(sym)); }
     void setObject(JSObject& obj) { setBarriered(JS::ObjectValue(obj)); }
     void setPrivateGCThing(js::gc::Cell* cell) { setBarriered(JS::PrivateGCThingValue(cell)); }
 
     bool setNumber(uint32_t ui) {
         if (ui > JSVAL_INT_MAX) {
             setDouble((double)ui);
             return false;
-        } else {
-            setInt32((int32_t)ui);
-            return true;
         }
+        setInt32((int32_t)ui);
+        return true;
+
     }
 
     bool setNumber(double d) {
         int32_t i;
         if (mozilla::NumberIsInt32(d, &i)) {
             setInt32(i);
             return true;
         }
--- a/js/src/builtin/TypedObject.h
+++ b/js/src/builtin/TypedObject.h
@@ -100,23 +100,24 @@ namespace js {
  * simple C casting from double to int32_t gets things wrong
  * for values like 0xF0000000.
  */
 template <typename T>
 static T ConvertScalar(double d)
 {
     if (TypeIsFloatingPoint<T>()) {
         return T(d);
-    } else if (TypeIsUnsigned<T>()) {
+    }
+    if (TypeIsUnsigned<T>()) {
         uint32_t n = JS::ToUint32(d);
         return T(n);
-    } else {
-        int32_t n = JS::ToInt32(d);
-        return T(n);
     }
+    int32_t n = JS::ToInt32(d);
+    return T(n);
+
 }
 
 namespace type {
 
 enum Kind {
     Scalar = JS_TYPEREPR_SCALAR_KIND,
     Reference = JS_TYPEREPR_REFERENCE_KIND,
     Simd = JS_TYPEREPR_SIMD_KIND,
--- a/js/src/ctypes/CTypes.cpp
+++ b/js/src/ctypes/CTypes.cpp
@@ -3525,17 +3525,18 @@ ImplicitConvert(JSContext* cx,
         (*char16Buffer)[sourceLength] = 0;
         break;
       }
       default:
         return ConvError(cx, targetType, val, convType, funObj, argIndex,
                          arrObj, arrIndex);
       }
       break;
-    } else if (val.isObject() && JS_IsArrayBufferObject(valObj)) {
+    }
+      if (val.isObject() && JS_IsArrayBufferObject(valObj)) {
       // Convert ArrayBuffer to pointer without any copy. This is only valid
       // when converting an argument to a function call, as it is possible for
       // the pointer to be invalidated by anything that runs JS code. (It is
       // invalid to invoke JS code from a ctypes function call.)
       if (convType != ConversionType::Argument) {
         return ConvError(cx, targetType, val, convType, funObj, argIndex,
                          arrObj, arrIndex);
       }
@@ -3547,23 +3548,25 @@ ImplicitConvert(JSContext* cx,
           MOZ_ASSERT(!isShared); // Because ArrayBuffer
       }
       if (!ptr) {
         return ConvError(cx, targetType, val, convType, funObj, argIndex,
                          arrObj, arrIndex);
       }
       *static_cast<void**>(buffer) = ptr;
       break;
-    } else if (val.isObject() && JS_IsSharedArrayBufferObject(valObj)) {
+    }
+    if (val.isObject() && JS_IsSharedArrayBufferObject(valObj)) {
       // CTypes has not yet opted in to allowing shared memory pointers
       // to escape.  Exporting a pointer to the shared buffer without
       // indicating sharedness would expose client code to races.
       return ConvError(cx, targetType, val, convType, funObj, argIndex,
                        arrObj, arrIndex);
-    } else if (val.isObject() && JS_IsArrayBufferViewObject(valObj)) {
+    }
+    if (val.isObject() && JS_IsArrayBufferViewObject(valObj)) {
       // Same as ArrayBuffer, above, though note that this will take the
       // offset of the view into account.
       if(!CanConvertTypedArrayItemTo(baseType, valObj, cx)) {
         return ConvError(cx, targetType, val, convType, funObj, argIndex,
                          arrObj, arrIndex);
       }
       if (convType != ConversionType::Argument) {
         return ConvError(cx, targetType, val, convType, funObj, argIndex,
@@ -3710,17 +3713,18 @@ ImplicitConvert(JSContext* cx,
         bool isShared;
         SharedMem<void*> src =
             (bufferShared ?
              SharedMem<void*>::shared(JS_GetSharedArrayBufferData(valObj, &isShared, nogc)) :
              SharedMem<void*>::unshared(JS_GetArrayBufferData(valObj, &isShared, nogc)));
         MOZ_ASSERT(isShared == bufferShared);
         jit::AtomicOperations::memcpySafeWhenRacy(target, src, sourceLength);
         break;
-      } else if (JS_IsTypedArrayObject(valObj)) {
+      }
+      if (JS_IsTypedArrayObject(valObj)) {
         // Check that array is consistent with type, then
         // copy the array.  It is OK to copy from shared to unshared
         // or vice versa.
         if (!CanConvertTypedArrayItemTo(baseType, valObj, cx)) {
           return ConvError(cx, targetType, val, convType, funObj, argIndex,
                            arrObj, arrIndex);
         }
 
@@ -3734,22 +3738,22 @@ ImplicitConvert(JSContext* cx,
         }
         SharedMem<void*> target = SharedMem<void*>::unshared(buffer);
         JS::AutoCheckCannotGC nogc;
         bool isShared;
         SharedMem<void*> src =
             SharedMem<void*>::shared(JS_GetArrayBufferViewData(valObj, &isShared, nogc));
         jit::AtomicOperations::memcpySafeWhenRacy(target, src, sourceLength);
         break;
-      } else {
+      }
         // Don't implicitly convert to string. Users can implicitly convert
         // with `String(x)` or `""+x`.
         return ConvError(cx, targetType, val, convType, funObj, argIndex,
                          arrObj, arrIndex);
-      }
+
     }
     break;
   }
   case TYPE_struct: {
     if (val.isObject() && !sourceData) {
       // Enumerate the properties of the object; if they match the struct
       // specification, convert the fields.
       Rooted<IdVector> props(cx, IdVector(cx));
--- a/js/src/ds/SplayTree.h
+++ b/js/src/ds/SplayTree.h
@@ -173,17 +173,17 @@ class SplayTree
         MOZ_ASSERT(root);
         Node* node = root;
         Node* parent;
         do {
             parent = node;
             int c = C::compare(v, node->item);
             if (c == 0)
                 return node;
-            else if (c < 0)
+            if (c < 0)
                 node = node->left;
             else
                 node = node->right;
         } while (node);
         return parent;
     }
 
     Node* allocateNode(const T& v)
--- a/js/src/gc/Zone.h
+++ b/js/src/gc/Zone.h
@@ -210,39 +210,39 @@ struct Zone : public JS::shadow::Zone,
         gcState_ = state;
         if (state == Finished)
             notifyObservingDebuggers();
     }
 
     bool isCollecting() const {
         if (runtimeFromMainThread()->isHeapCollecting())
             return gcState_ != NoGC;
-        else
-            return needsIncrementalBarrier();
+
+        return needsIncrementalBarrier();
     }
 
     bool isCollectingFromAnyThread() const {
         if (runtimeFromAnyThread()->isHeapCollecting())
             return gcState_ != NoGC;
-        else
-            return needsIncrementalBarrier();
+
+       return needsIncrementalBarrier();
     }
 
     // If this returns true, all object tracing must be done with a GC marking
     // tracer.
     bool requireGCTracer() const {
         JSRuntime* rt = runtimeFromAnyThread();
         return rt->isHeapMajorCollecting() && !rt->gc.isHeapCompacting() && gcState_ != NoGC;
     }
 
     bool isGCMarking() {
         if (runtimeFromMainThread()->isHeapCollecting())
             return gcState_ == Mark || gcState_ == MarkGray;
-        else
-            return needsIncrementalBarrier();
+
+        return needsIncrementalBarrier();
     }
 
     bool wasGCStarted() const { return gcState_ != NoGC; }
     bool isGCMarkingBlack() { return gcState_ == Mark; }
     bool isGCMarkingGray() { return gcState_ == MarkGray; }
     bool isGCSweeping() { return gcState_ == Sweep; }
     bool isGCFinished() { return gcState_ == Finished; }
     bool isGCCompacting() { return gcState_ == Compact; }
--- a/js/src/irregexp/RegExpEngine.h
+++ b/js/src/irregexp/RegExpEngine.h
@@ -621,20 +621,20 @@ class Interval
   public:
     Interval() : from_(kNone), to_(kNone) { }
 
     Interval(int from, int to) : from_(from), to_(to) { }
 
     Interval Union(Interval that) {
         if (that.from_ == kNone)
             return *this;
-        else if (from_ == kNone)
+        if (from_ == kNone)
             return that;
-        else
-            return Interval(Min(from_, that.from_), Max(to_, that.to_));
+
+        return Interval(Min(from_, that.from_), Max(to_, that.to_));
     }
 
     bool Contains(int value) {
         return (from_ <= value) && (value <= to_);
     }
 
     bool is_empty() { return from_ == kNone; }
 
--- a/js/src/irregexp/RegExpParser.h
+++ b/js/src/irregexp/RegExpParser.h
@@ -93,24 +93,24 @@ class BufferedVector
         return result;
     }
 
     T* Get(int i) {
         MOZ_ASSERT((0 <= i) && (i < length()));
         if (list_ == nullptr) {
             MOZ_ASSERT(0 == i);
             return last_;
-        } else {
+        }
             if (size_t(i) == list_->length()) {
                 MOZ_ASSERT(last_ != nullptr);
                 return last_;
-            } else {
-                return (*list_)[i];
             }
-        }
+            return (*list_)[i];
+
+
     }
 
     void Clear() {
         list_ = nullptr;
         last_ = nullptr;
     }
 
     int length() {
--- a/js/src/jit/MoveResolver.h
+++ b/js/src/jit/MoveResolver.h
@@ -130,21 +130,23 @@ class MoveOperand
                 // Assume that register pairs are aligned on even registers.
                 MOZ_ASSERT(!evenReg().aliases(other.oddReg()));
                 MOZ_ASSERT(!oddReg().aliases(other.evenReg()));
                 // Pair of registers are composed of consecutive registers, thus
                 // if the first registers are aliased, then the second registers
                 // are aliased too.
                 MOZ_ASSERT(evenReg().aliases(other.evenReg()) == oddReg().aliases(other.oddReg()));
                 return evenReg().aliases(other.evenReg());
-            } else if (other.isGeneralReg()) {
+            }
+            if (other.isGeneralReg()) {
                 MOZ_ASSERT(isGeneralRegPair());
                 return evenReg().aliases(other.reg()) ||
                        oddReg().aliases(other.reg());
-            } else if (isGeneralReg()) {
+            }
+            if (isGeneralReg()) {
                 MOZ_ASSERT(other.isGeneralRegPair());
                 return other.evenReg().aliases(reg()) ||
                        other.oddReg().aliases(reg());
             }
             return false;
         }
 
         if (kind_ != other.kind_)
--- a/js/src/jsarray.cpp
+++ b/js/src/jsarray.cpp
@@ -1092,19 +1092,19 @@ ArrayJoinDenseKernel(JSContext* cx, Sepa
              * Object stringifying could modify the initialized length or make
              * the array sparse. Delegate it to a separate loop to keep this
              * one tight.
              *
              * Symbol stringifying is a TypeError, so into the slow path
              * with those as well.
              */
             break;
-        } else {
-            MOZ_ASSERT(elem.isMagic(JS_ELEMENTS_HOLE) || elem.isNullOrUndefined());
         }
+        MOZ_ASSERT(elem.isMagic(JS_ELEMENTS_HOLE) || elem.isNullOrUndefined());
+
 
         if (++(*numProcessed) != length && !sepOp(cx, sb))
             return DenseElementResult::Failure;
     }
 
     return DenseElementResult::Incomplete;
 }
 
--- a/js/src/perf/pm_linux.cpp
+++ b/js/src/perf/pm_linux.cpp
@@ -297,14 +297,14 @@ PerfMeasurement::canMeasureSomething()
     memset(&attr, 0, sizeof(attr));
     attr.size = sizeof(attr);
     attr.type = PERF_TYPE_MAX;
 
     int fd = sys_perf_event_open(&attr, 0, -1, -1, 0);
     if (fd >= 0) {
         close(fd);
         return true;
-    } else {
-        return errno != ENOSYS;
     }
+    return errno != ENOSYS;
+
 }
 
 } // namespace JS
--- a/js/src/vm/Shape-inl.h
+++ b/js/src/vm/Shape-inl.h
@@ -52,19 +52,19 @@ Shape::search(ExclusiveContext* cx, Shap
         return entry.shape();
     }
 
     if (start->numLinearSearches() == LINEAR_SEARCHES_MAX) {
         if (start->isBigEnoughForAShapeTable()) {
             if (Shape::hashify(cx, start)) {
                 ShapeTable::Entry& entry = start->table().search<Adding>(id);
                 return entry.shape();
-            } else {
-                cx->recoverFromOutOfMemory();
             }
+            cx->recoverFromOutOfMemory();
+
         }
         /*
          * No table built -- there weren't enough entries, or OOM occurred.
          * Don't increment numLinearSearches, to keep hasTable() false.
          */
         MOZ_ASSERT(!start->hasTable());
     } else {
         start->incrementNumLinearSearches();
--- a/js/src/vm/TraceLogging.cpp
+++ b/js/src/vm/TraceLogging.cpp
@@ -227,26 +227,26 @@ TraceLoggerThread::enable(JSContext* cx)
             MOZ_ASSERT(it.isIonJS() || it.isBaselineJS());
 
             script = it.script();
             engine = it.isIonJS() ? TraceLogger_IonMonkey : TraceLogger_Baseline;
         } else if (act->isWasm()) {
             JS_ReportErrorNumber(cx, GetErrorMessage, nullptr, JSMSG_TRACELOGGER_ENABLE_FAIL,
                                  "not yet supported in wasm code");
             return false;
-        } else {
-            MOZ_ASSERT(act->isInterpreter());
-            InterpreterFrame* fp = act->asInterpreter()->current();
-            MOZ_ASSERT(!fp->runningInJit());
+        }
+        MOZ_ASSERT(act->isInterpreter());
+        InterpreterFrame* fp = act->asInterpreter()->current();
+        MOZ_ASSERT(!fp->runningInJit());
 
-            script = fp->script();
-            engine = TraceLogger_Interpreter;
-            if (script->compartment() != cx->compartment())
-                return fail(cx, "compartment mismatch");
-        }
+        script = fp->script();
+        engine = TraceLogger_Interpreter;
+        if (script->compartment() != cx->compartment())
+            return fail(cx, "compartment mismatch");
+
 
         TraceLoggerEvent event(this, TraceLogger_Scripts, script);
         startEvent(event);
         startEvent(engine);
     }
 
     return true;
 }
--- a/js/src/vm/TypeInference-inl.h
+++ b/js/src/vm/TypeInference-inl.h
@@ -864,25 +864,27 @@ TypeSet::Type::trace(JSTracer* trc)
 inline bool
 TypeSet::hasType(Type type) const
 {
     if (unknown())
         return true;
 
     if (type.isUnknown()) {
         return false;
-    } else if (type.isPrimitive()) {
+    }
+    if (type.isPrimitive()) {
         return !!(flags & PrimitiveTypeFlag(type.primitive()));
-    } else if (type.isAnyObject()) {
+    }
+    if (type.isAnyObject()) {
         return !!(flags & TYPE_FLAG_ANYOBJECT);
-    } else {
-        return !!(flags & TYPE_FLAG_ANYOBJECT) ||
-               TypeHashSet::Lookup<ObjectKey*, ObjectKey, ObjectKey>
-                   (objectSet, baseObjectCount(), type.objectKey()) != nullptr;
     }
+    return !!(flags & TYPE_FLAG_ANYOBJECT) ||
+           TypeHashSet::Lookup<ObjectKey*, ObjectKey, ObjectKey>
+               (objectSet, baseObjectCount(), type.objectKey()) != nullptr;
+
 }
 
 inline void
 TypeSet::setBaseObjectCount(uint32_t count)
 {
     MOZ_ASSERT(count <= TYPE_FLAG_DOMOBJECT_COUNT_LIMIT);
     flags = (flags & ~TYPE_FLAG_OBJECT_COUNT_MASK)
           | (count << TYPE_FLAG_OBJECT_COUNT_SHIFT);
--- a/js/xpconnect/wrappers/XrayWrapper.cpp
+++ b/js/xpconnect/wrappers/XrayWrapper.cpp
@@ -519,45 +519,47 @@ JSXrayTraits::resolveOwnProperty(JSConte
         // Note that, as far as JS observables go, Arrays are just Objects with
         // a different prototype and a magic (own, non-configurable) |.length| that
         // serves as a non-tight upper bound on |own| indexed properties. So while
         // it's tempting to try to impose some sort of structure on what Arrays
         // "should" look like over Xrays, the underlying object is squishy enough
         // that it makes sense to just treat them like Objects for Xray purposes.
         if (key == JSProto_Object || key == JSProto_Array) {
             return getOwnPropertyFromWrapperIfSafe(cx, wrapper, id, desc);
-        } else if (IsTypedArrayKey(key)) {
+        }
+        if (IsTypedArrayKey(key)) {
             if (IsArrayIndex(GetArrayIndexFromId(cx, id))) {
                 // WebExtensions can't use cloneInto(), so we just let them do
                 // the slow thing to maximize compatibility.
                 if (CompartmentPrivate::Get(CurrentGlobalOrNull(cx))->isWebExtensionContentScript) {
                     Rooted<PropertyDescriptor> innerDesc(cx);
                     {
                         JSAutoCompartment ac(cx, target);
                         if (!JS_GetOwnPropertyDescriptorById(cx, target, id, &innerDesc))
                             return false;
                     }
                     if (innerDesc.isDataDescriptor() && innerDesc.value().isNumber()) {
                         desc.setValue(innerDesc.value());
                         desc.object().set(wrapper);
                     }
                     return true;
-                } else {
+                }
                     JS_ReportError(cx, "Accessing TypedArray data over Xrays is slow, and forbidden "
                                        "in order to encourage performant code. To copy TypedArrays "
                                        "across origin boundaries, consider using Components.utils.cloneInto().");
                     return false;
-                }
+
             }
         } else if (key == JSProto_Function) {
             if (id == GetRTIdByIndex(cx, XPCJSRuntime::IDX_LENGTH)) {
                 FillPropertyDescriptor(desc, wrapper, JSPROP_PERMANENT | JSPROP_READONLY,
                                        NumberValue(JS_GetFunctionArity(JS_GetObjectFunction(target))));
                 return true;
-            } else if (id == GetRTIdByIndex(cx, XPCJSRuntime::IDX_NAME)) {
+            }
+            if (id == GetRTIdByIndex(cx, XPCJSRuntime::IDX_NAME)) {
                 RootedString fname(cx, JS_GetFunctionId(JS_GetObjectFunction(target)));
                 FillPropertyDescriptor(desc, wrapper, JSPROP_PERMANENT | JSPROP_READONLY,
                                        fname ? StringValue(fname) : JS_GetEmptyStringValue(cx));
             } else {
                 // Look for various static properties/methods and the
                 // 'prototype' property.
                 JSProtoKey standardConstructor = constructorFor(holder);
                 if (standardConstructor != JSProto_Null) {
@@ -845,17 +847,18 @@ JSXrayTraits::enumerateNames(JSContext* 
                     RootedId id(cx, targetProps[i]);
                     if (!getOwnPropertyFromTargetIfSafe(cx, target, wrapper, id, &desc))
                         return false;
                     if (desc.object())
                         props.infallibleAppend(id);
                 }
             }
             return true;
-        } else if (IsTypedArrayKey(key)) {
+        }
+        if (IsTypedArrayKey(key)) {
             uint32_t length = JS_GetTypedArrayLength(target);
             // TypedArrays enumerate every indexed property in range, but
             // |length| is a getter that lives on the proto, like it should be.
             if (!props.reserve(length))
                 return false;
             for (int32_t i = 0; i <= int32_t(length - 1); ++i)
                 props.infallibleAppend(INT_TO_JSID(i));
         } else if (key == JSProto_Function) {