diff options
| author | Christian Kandeler <christian.kandeler@digia.com> | 2013-09-19 11:29:04 +0200 |
|---|---|---|
| committer | Christian Kandeler <christian.kandeler@digia.com> | 2013-09-19 11:38:47 +0200 |
| commit | e0d292b08046c5a257b23cd45a7bebe0849bc42c (patch) | |
| tree | 32241f996d7d01467d748001af8610154005634a /src/lib/language | |
| parent | 2c442b7b7e7a80522743f4b2931f615e1fc9beb5 (diff) | |
| download | qbs-e0d292b08046c5a257b23cd45a7bebe0849bc42c.tar.gz | |
Add shortcuts to some equality checks.
Comparing the pointers first is both faster in case the two references
actually point to the same object and also allows us to do a null
pointer check before accessing any members.
Note that doing the null pointer check in operator== means that we have
already applied the operator* to the object. which is a bit... dubious.
However, since no actual access to any data happens, this is very
unlikely to cause problems, and it has the advantage that we will catch
all comparisons, not just the ones that we would explicitly route
through some wrapper function we would write otherwise.
Change-Id: Ia63508ae925520565956086403fa1eb6494e3de8
Reviewed-by: Joerg Bornemann <joerg.bornemann@digia.com>
Diffstat (limited to 'src/lib/language')
| -rw-r--r-- | src/lib/language/language.cpp | 20 |
1 files changed, 16 insertions, 4 deletions
diff --git a/src/lib/language/language.cpp b/src/lib/language/language.cpp index 3489f03d8..531abf8f2 100644 --- a/src/lib/language/language.cpp +++ b/src/lib/language/language.cpp @@ -233,6 +233,10 @@ void ResolvedFileContext::store(PersistentPool &pool) const bool operator==(const ResolvedFileContext &a, const ResolvedFileContext &b) { + if (&a == &b) + return true; + if (!!&a != !!&b) + return false; return a.filePath == b.filePath && a.jsExtensions == b.jsExtensions && a.jsImports == b.jsImports; @@ -274,6 +278,10 @@ void ScriptFunction::store(PersistentPool &pool) const bool operator==(const ScriptFunction &a, const ScriptFunction &b) { + if (&a == &b) + return true; + if (!!&a != !!&b) + return false; return a.sourceCode == b.sourceCode && a.location == b.location && *a.fileContext == *b.fileContext; @@ -297,6 +305,10 @@ void ResolvedModule::store(PersistentPool &pool) const bool operator==(const ResolvedModule &m1, const ResolvedModule &m2) { + if (&m1 == &m2) + return true; + if (!!&m1 != !!&m2) + return false; return m1.name == m2.name && m1.moduleDependencies.toSet() == m2.moduleDependencies.toSet() && *m1.setupBuildEnvironmentScript == *m2.setupBuildEnvironmentScript @@ -305,10 +317,6 @@ bool operator==(const ResolvedModule &m1, const ResolvedModule &m2) static bool modulesAreEqual(const ResolvedModuleConstPtr &m1, const ResolvedModuleConstPtr &m2) { - if (!m1 && !m2) - return true; - if ((!m1 && m2) || (m1 && !m2)) - return false; return *m1 == *m2; } @@ -978,6 +986,10 @@ QString keyFromElem(const ResolvedTransformerConstPtr &t) { return t->transform- bool operator==(const SourceArtifact &sa1, const SourceArtifact &sa2) { + if (&sa1 == &sa2) + return true; + if (!!&sa1 != !!&sa2) + return false; return sa1.absoluteFilePath == sa2.absoluteFilePath && sa1.fileTags == sa2.fileTags && sa1.overrideFileTags == sa2.overrideFileTags |
