From e69a920f18d099e07d165ce70a94365603c4300e Mon Sep 17 00:00:00 2001 From: Uwe Date: Mon, 18 Jul 2022 03:12:01 +0200 Subject: [PATCH] [App] remove superfluous nullptr checks --- src/App/DocumentPyImp.cpp | 4 ++-- src/App/Enumeration.cpp | 4 ++-- src/App/Expression.cpp | 12 +++++------ src/App/ExtensionContainer.cpp | 28 ++++++++++++------------- src/App/ExtensionContainerPyImp.cpp | 10 ++++----- src/App/FeaturePython.cpp | 8 +++---- src/App/FeaturePythonPyImp.inl | 2 +- src/App/ObjectIdentifier.cpp | 31 ++++++++++++++-------------- src/App/PropertyExpressionEngine.cpp | 2 +- src/App/PropertyLinks.cpp | 4 ++-- src/App/Range.cpp | 2 +- src/App/Transactions.cpp | 2 +- 12 files changed, 55 insertions(+), 54 deletions(-) diff --git a/src/App/DocumentPyImp.cpp b/src/App/DocumentPyImp.cpp index b7caacbe9a..40d61c94e5 100644 --- a/src/App/DocumentPyImp.cpp +++ b/src/App/DocumentPyImp.cpp @@ -808,7 +808,7 @@ PyObject *DocumentPy::getCustomAttributes(const char* attr) const App::Property* prop = getPropertyContainerPtr()->getPropertyByName(attr); if (prop) return nullptr; - if (this->ob_type->tp_dict == nullptr) { + if (!this->ob_type->tp_dict) { if (PyType_Ready(this->ob_type) < 0) return nullptr; } @@ -830,7 +830,7 @@ int DocumentPy::setCustomAttributes(const char* attr, PyObject *) App::Property* prop = getPropertyContainerPtr()->getPropertyByName(attr); if (prop) return 0; - if (this->ob_type->tp_dict == nullptr) { + if (!this->ob_type->tp_dict) { if (PyType_Ready(this->ob_type) < 0) return 0; } diff --git a/src/App/Enumeration.cpp b/src/App/Enumeration.cpp index affad5084a..e0dfec6d1d 100644 --- a/src/App/Enumeration.cpp +++ b/src/App/Enumeration.cpp @@ -274,7 +274,7 @@ bool Enumeration::operator==(const Enumeration &other) const for (size_t i = 0; i < enumArray.size(); ++i) { if (enumArray[i]->data() == other.enumArray[i]->data()) continue; - if (enumArray[i]->data() == nullptr || other.enumArray[i]->data() == nullptr) + if (!enumArray[i]->data() || !other.enumArray[i]->data()) return false; if (!enumArray[i]->isEqual(other.enumArray[i]->data())) return false; @@ -284,7 +284,7 @@ bool Enumeration::operator==(const Enumeration &other) const bool Enumeration::operator==(const char *other) const { - if (getCStr() == nullptr) { + if (!getCStr()) { return false; } diff --git a/src/App/Expression.cpp b/src/App/Expression.cpp index a682d9422a..83d5dc014e 100644 --- a/src/App/Expression.cpp +++ b/src/App/Expression.cpp @@ -1976,11 +1976,11 @@ Py::Object FunctionExpression::evalAggregate( if (!p) continue; - if ((qp = freecad_dynamic_cast(p)) != nullptr) + if ((qp = freecad_dynamic_cast(p))) c->collect(qp->getQuantityValue()); - else if ((fp = freecad_dynamic_cast(p)) != nullptr) + else if ((fp = freecad_dynamic_cast(p))) c->collect(Quantity(fp->getValue())); - else if ((ip = freecad_dynamic_cast(p)) != nullptr) + else if ((ip = freecad_dynamic_cast(p))) c->collect(Quantity(ip->getValue())); else _EXPR_THROW("Invalid property type for aggregate.", owner); @@ -2858,7 +2858,7 @@ Expression *ConditionalExpression::simplify() const std::unique_ptr e(condition->simplify()); NumberExpression * v = freecad_dynamic_cast(e.get()); - if (v == nullptr) + if (!v) return new ConditionalExpression(owner, condition->simplify(), trueExpr->simplify(), falseExpr->simplify()); else { if (fabs(v->getValue()) > 0.5) @@ -3327,7 +3327,7 @@ Expression * App::ExpressionParser::parse(const App::DocumentObject *owner, cons if (result != 0) throw ParserError("Failed to parse expression."); - if (ScanResult == nullptr) + if (!ScanResult) throw ParserError("Unknown error in expression"); if (valueExpression) @@ -3355,7 +3355,7 @@ UnitExpression * ExpressionParser::parseUnit(const App::DocumentObject *owner, c if (result != 0) throw ParserError("Failed to parse expression."); - if (ScanResult == nullptr) + if (!ScanResult) throw ParserError("Unknown error in expression"); // Simplify expression diff --git a/src/App/ExtensionContainer.cpp b/src/App/ExtensionContainer.cpp index b2fc999ba8..49e7763a42 100644 --- a/src/App/ExtensionContainer.cpp +++ b/src/App/ExtensionContainer.cpp @@ -204,12 +204,12 @@ short int ExtensionContainer::getPropertyType(const char* name) const { const char* ExtensionContainer::getPropertyName(const Property* prop) const { const char* res = App::PropertyContainer::getPropertyName(prop); - if(res != nullptr) + if (res) return res; - for(const auto& entry : _extensions) { + for (const auto& entry : _extensions) { res = entry.second->extensionGetPropertyName(prop); - if(res != nullptr) + if (res) return res; } @@ -219,12 +219,12 @@ const char* ExtensionContainer::getPropertyName(const Property* prop) const { const char* ExtensionContainer::getPropertyGroup(const Property* prop) const { const char* res = App::PropertyContainer::getPropertyGroup(prop); - if(res != nullptr) + if (res) return res; - for(const auto& entry : _extensions) { + for (const auto& entry : _extensions) { res = entry.second->extensionGetPropertyGroup(prop); - if(res != nullptr) + if (res) return res; } @@ -234,12 +234,12 @@ const char* ExtensionContainer::getPropertyGroup(const Property* prop) const { const char* ExtensionContainer::getPropertyGroup(const char* name) const { const char* res = App::PropertyContainer::getPropertyGroup(name); - if(res != nullptr) + if (res) return res; - for(const auto& entry : _extensions) { + for (const auto& entry : _extensions) { res = entry.second->extensionGetPropertyGroup(name); - if(res != nullptr) + if (res) return res; } @@ -250,12 +250,12 @@ const char* ExtensionContainer::getPropertyGroup(const char* name) const { const char* ExtensionContainer::getPropertyDocumentation(const Property* prop) const { const char* res = App::PropertyContainer::getPropertyDocumentation(prop); - if(res != nullptr) + if (res) return res; - for(const auto& entry : _extensions) { + for (const auto& entry : _extensions) { res = entry.second->extensionGetPropertyDocumentation(prop); - if(res != nullptr) + if (res) return res; } @@ -265,12 +265,12 @@ const char* ExtensionContainer::getPropertyDocumentation(const Property* prop) c const char* ExtensionContainer::getPropertyDocumentation(const char* name) const { const char* res = App::PropertyContainer::getPropertyDocumentation(name); - if(res != nullptr) + if (res) return res; for(const auto& entry : _extensions) { res = entry.second->extensionGetPropertyDocumentation(name); - if(res != nullptr) + if (res) return res; } diff --git a/src/App/ExtensionContainerPyImp.cpp b/src/App/ExtensionContainerPyImp.cpp index 76b03308cf..6a93b0ad77 100644 --- a/src/App/ExtensionContainerPyImp.cpp +++ b/src/App/ExtensionContainerPyImp.cpp @@ -43,7 +43,7 @@ std::string ExtensionContainerPy::representation(void) const int ExtensionContainerPy::initialization() { - if (this->ob_type->tp_dict == nullptr) { + if (!this->ob_type->tp_dict) { if (PyType_Ready(this->ob_type) < 0) return 0; } @@ -61,7 +61,7 @@ int ExtensionContainerPy::initialization() { // make sure to do the initialization only once if (meth->ml_name) { PyObject* item = PyDict_GetItemString(dict, meth->ml_name); - if (item == nullptr) { + if (!item) { // Note: this adds the methods to the type object to make sure // it appears in the call tips. The function will not be bound // to an instance @@ -69,7 +69,7 @@ int ExtensionContainerPy::initialization() { while (meth->ml_name) { PyObject *func; func = PyCFunction_New(meth, 0); - if (func == nullptr) + if (!func) break; if (PyDict_SetItemString(dict, meth->ml_name, func) < 0) break; @@ -238,7 +238,7 @@ PyObject* ExtensionContainerPy::addExtension(PyObject *args) { // make sure to do the initialization only once if (meth->ml_name) { PyObject* item = PyDict_GetItemString(dict, meth->ml_name); - if (item == nullptr) { + if (!item) { // Note: this adds the methods to the type object to make sure // it appears in the call tips. The function will not be bound // to an instance @@ -246,7 +246,7 @@ PyObject* ExtensionContainerPy::addExtension(PyObject *args) { while (meth->ml_name) { PyObject *func; func = PyCFunction_New(meth, 0); - if (func == nullptr) + if (!func) break; if (PyDict_SetItemString(dict, meth->ml_name, func) < 0) break; diff --git a/src/App/FeaturePython.cpp b/src/App/FeaturePython.cpp index 0fd6c3a4d2..1baffbdc14 100644 --- a/src/App/FeaturePython.cpp +++ b/src/App/FeaturePython.cpp @@ -129,14 +129,14 @@ bool FeaturePythonImp::mustExecute() const void FeaturePythonImp::onBeforeChange(const Property* prop) { - if(py_onBeforeChange.isNone()) + if (py_onBeforeChange.isNone()) return; // Run the execute method of the proxy object. Base::PyGILStateLocker lock; try { const char *prop_name = object->getPropertyName(prop); - if(prop_name == nullptr) + if (!prop_name) return; if (has__object__) { Py::Tuple args(1); @@ -184,13 +184,13 @@ bool FeaturePythonImp::onBeforeChangeLabel(std::string &newLabel) void FeaturePythonImp::onChanged(const Property* prop) { - if(py_onChanged.isNone()) + if (py_onChanged.isNone()) return; // Run the execute method of the proxy object. Base::PyGILStateLocker lock; try { const char *prop_name = object->getPropertyName(prop); - if(prop_name == nullptr) + if (!prop_name) return; if (has__object__) { Py::Tuple args(1); diff --git a/src/App/FeaturePythonPyImp.inl b/src/App/FeaturePythonPyImp.inl index 0e89e651f7..8abfda8b34 100644 --- a/src/App/FeaturePythonPyImp.inl +++ b/src/App/FeaturePythonPyImp.inl @@ -168,7 +168,7 @@ PyObject *FeaturePythonPyT::_getattr(const char *attr) // Return the default dict PyTypeObject *tp = this->ob_type; // register type if needed - if (tp->tp_dict == nullptr) { + if (!tp->tp_dict) { if (PyType_Ready(tp) < 0) return nullptr; } diff --git a/src/App/ObjectIdentifier.cpp b/src/App/ObjectIdentifier.cpp index 3d1c2589a9..dc2dc26ab3 100644 --- a/src/App/ObjectIdentifier.cpp +++ b/src/App/ObjectIdentifier.cpp @@ -855,7 +855,7 @@ App::DocumentObject * ObjectIdentifier::getDocumentObject(const App::Document * for (std::vector::iterator j = docObjects.begin(); j != docObjects.end(); ++j) { if (strcmp((*j)->Label.getValue(), static_cast(name)) == 0) { // Found object with matching label - if (objectByLabel != nullptr) { + if (objectByLabel) { FC_WARN("duplicate object label " << doc->getName() << '#' << name); return nullptr; } @@ -863,13 +863,13 @@ App::DocumentObject * ObjectIdentifier::getDocumentObject(const App::Document * } } - if (objectByLabel == nullptr && objectById == nullptr) // Not found at all + if (!objectByLabel && !objectById) // Not found at all return nullptr; - else if (objectByLabel == nullptr) { // Found by name + else if (!objectByLabel) { // Found by name flags.set(ResolveByIdentifier); return objectById; } - else if (objectById == nullptr) { // Found by label + else if (!objectById) { // Found by label flags.set(ResolveByLabel); return objectByLabel; } @@ -913,7 +913,7 @@ void ObjectIdentifier::resolve(ResolveResults &results) const results.propertyIndex = 0; // Assume document name and object name from owner if not found - if (results.resolvedDocument == nullptr) { + if (!results.resolvedDocument) { if (documentName.getString().size() > 0) { if(docAmbiguous) results.flags.set(ResolveAmbiguous); @@ -921,7 +921,7 @@ void ObjectIdentifier::resolve(ResolveResults &results) const } results.resolvedDocument = owner->getDocument(); - if (results.resolvedDocument == nullptr) + if (!results.resolvedDocument) return; } @@ -1029,7 +1029,7 @@ Document * ObjectIdentifier::getDocument(String name, bool *ambiguous) const for (std::vector::const_iterator i = docs.begin(); i != docs.end(); ++i) { if ((*i)->Label.getValue() == name.getString()) { /* Multiple hits for same label? */ - if (docByLabel != nullptr) { + if (docByLabel) { if(ambiguous) *ambiguous = true; return nullptr; } @@ -1038,17 +1038,18 @@ Document * ObjectIdentifier::getDocument(String name, bool *ambiguous) const } /* Not found on id? */ - if (docById == nullptr) + if (!docById) return docByLabel; // Either not found at all, or on label else { /* Not found on label? */ - if (docByLabel == nullptr) /* Then return doc by id */ + if (!docByLabel) /* Then return doc by id */ return docById; /* docByLabel and docById could be equal; that is ok */ - if(docByLabel==docById) + if (docByLabel == docById) return docById; - if(ambiguous) *ambiguous = true; + if (ambiguous) + *ambiguous = true; return nullptr; } } @@ -1979,23 +1980,23 @@ ObjectIdentifier::ResolveResults::ResolveResults(const ObjectIdentifier &oi) std::string ObjectIdentifier::ResolveResults::resolveErrorString() const { std::ostringstream ss; - if (resolvedDocument == nullptr) { + if (!resolvedDocument) { if(flags.test(ResolveAmbiguous)) ss << "Ambiguous document name/label '" << resolvedDocumentName.getString() << "'"; else ss << "Document '" << resolvedDocumentName.toString() << "' not found"; - } else if (resolvedDocumentObject == nullptr) { + } else if (!resolvedDocumentObject) { if(flags.test(ResolveAmbiguous)) ss << "Ambiguous document object name '" << resolvedDocumentObjectName.getString() << "'"; else ss << "Document object '" << resolvedDocumentObjectName.toString() << "' not found"; - } else if (subObjectName.getString().size() && resolvedSubObject == nullptr) { + } else if (subObjectName.getString().size() && !resolvedSubObject) { ss << "Sub-object '" << resolvedDocumentObjectName.getString() << '.' << subObjectName.toString() << "' not found"; - } else if (resolvedProperty == nullptr) { + } else if (!resolvedProperty) { if(propertyType != PseudoShape && subObjectName.getString().size() && !boost::ends_with(subObjectName.getString(),".")) diff --git a/src/App/PropertyExpressionEngine.cpp b/src/App/PropertyExpressionEngine.cpp index 5f65e20cbe..95f8103670 100644 --- a/src/App/PropertyExpressionEngine.cpp +++ b/src/App/PropertyExpressionEngine.cpp @@ -724,7 +724,7 @@ void PropertyExpressionEngine::getPathsToDocumentObject(DocumentObject* obj, { DocumentObject * owner = freecad_dynamic_cast(getContainer()); - if (owner == nullptr || owner==obj) + if (!owner || owner==obj) return; for(auto &v : expressions) { diff --git a/src/App/PropertyLinks.cpp b/src/App/PropertyLinks.cpp index 4616ab12bc..f7beb8db48 100644 --- a/src/App/PropertyLinks.cpp +++ b/src/App/PropertyLinks.cpp @@ -1721,7 +1721,7 @@ void PropertyLinkSubList::setValues(const std::vector& lValue,c _lSubList.resize(lSubNames.size()); int i = 0; for (std::vector::const_iterator it = lSubNames.begin();it!=lSubNames.end();++it,++i) { - if (*it != nullptr) + if (*it) _lSubList[i] = *it; } updateElementReference(nullptr); @@ -1923,7 +1923,7 @@ DocumentObject *PropertyLinkSubList::getValue() const App::DocumentObject* ret = nullptr; //FIXME: cache this to avoid iterating each time, to improve speed for (std::size_t i = 0; i < this->_lValueList.size(); i++) { - if (ret == nullptr) + if (!ret) ret = this->_lValueList[i]; if (ret != this->_lValueList[i]) return nullptr; diff --git a/src/App/Range.cpp b/src/App/Range.cpp index 05a97294ad..d3391c91a9 100644 --- a/src/App/Range.cpp +++ b/src/App/Range.cpp @@ -44,7 +44,7 @@ Range::Range(const char * range, bool normalize) assert(range != nullptr); - if (strchr(range, ':') == nullptr) { + if (!strchr(range, ':')) { from = range; to = range; } diff --git a/src/App/Transactions.cpp b/src/App/Transactions.cpp index a345e375d2..8d703dbb4b 100644 --- a/src/App/Transactions.cpp +++ b/src/App/Transactions.cpp @@ -488,7 +488,7 @@ App::TransactionFactory* App::TransactionFactory::self = nullptr; TransactionFactory& TransactionFactory::instance() { - if (self == nullptr) + if (!self) self = new TransactionFactory; return *self; }