diff options
author | Chandler Carruth <chandlerc@gmail.com> | 2012-12-29 12:01:08 +0000 |
---|---|---|
committer | Chandler Carruth <chandlerc@gmail.com> | 2012-12-29 12:01:08 +0000 |
commit | f1757659dd59a0e07e8607fca8d3f052e04d0aec (patch) | |
tree | c9367a4bda1d130675d357e4b47efbce9fd0bb03 | |
parent | 2464e96f0a73cd9757a6fdec4faf10d751d267fa (diff) |
Try to re-structure the GCCVersion comparison routine to make it easier
to read and tell that it is a SWO -- we now descend through the
components and return a result at the first inequal component.
Also comment it a bit better and make it a total ordering by sorting on
the text of the suffix if necessary.
None of this should really be a visible change.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@171219 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r-- | lib/Driver/ToolChains.cpp | 41 |
1 files changed, 27 insertions, 14 deletions
diff --git a/lib/Driver/ToolChains.cpp b/lib/Driver/ToolChains.cpp index 7cde397bf9..426bcf16ef 100644 --- a/lib/Driver/ToolChains.cpp +++ b/lib/Driver/ToolChains.cpp @@ -966,20 +966,33 @@ Generic_GCC::GCCVersion Linux::GCCVersion::Parse(StringRef VersionText) { /// \brief Less-than for GCCVersion, implementing a Strict Weak Ordering. bool Generic_GCC::GCCVersion::operator<(const GCCVersion &RHS) const { - if (Major < RHS.Major) return true; if (Major > RHS.Major) return false; - if (Minor < RHS.Minor) return true; if (Minor > RHS.Minor) return false; - - // Note that we rank versions with *no* patch specified is better than ones - // hard-coding a patch version. Thus if only the RHS or LHS has no patch, - // it wins. - if (RHS.Patch == -1 && Patch != -1) return true; - if (RHS.Patch != -1 && Patch == -1) return false; - if (Patch < RHS.Patch) return true; if (Patch > RHS.Patch) return false; - if (PatchSuffix == RHS.PatchSuffix) return false; - - // Finally, between completely tied version numbers, the version with the - // suffix loses as we prefer full releases. - if (RHS.PatchSuffix.empty()) return true; + if (Major != RHS.Major) + return Major < RHS.Major; + if (Minor != RHS.Minor) + return Minor < RHS.Minor; + if (Patch != RHS.Patch) { + // Note that versions without a specified patch sort higher than those with + // a patch. + if (RHS.Patch == -1) + return true; + if (Patch == -1) + return false; + + // Otherwise just sort on the patch itself. + return Patch < RHS.Patch; + } + if (PatchSuffix != RHS.PatchSuffix) { + // Sort empty suffixes higher. + if (RHS.PatchSuffix.empty()) + return true; + if (PatchSuffix.empty()) + return true; + + // Provide a lexicographic sort to make this a total ordering. + return PatchSuffix < RHS.PatchSuffix; + } + + // The versions are equal. return false; } |