Bumping manifests a=b2g-bump
[gecko.git] / xpcom / string / nsTStringComparator.cpp
blob13d285e8b4d94574ab7f5a04cc276e81e19a56a5
1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* vim: set ts=8 sts=2 et sw=2 tw=80: */
3 /* This Source Code Form is subject to the terms of the Mozilla Public
4 * License, v. 2.0. If a copy of the MPL was not distributed with this
5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
7 int NS_FASTCALL
8 Compare(const nsTSubstring_CharT::base_string_type& aLhs,
9 const nsTSubstring_CharT::base_string_type& aRhs,
10 const nsTStringComparator_CharT& comp)
12 typedef nsTSubstring_CharT::size_type size_type;
14 if (&aLhs == &aRhs) {
15 return 0;
18 nsTSubstring_CharT::const_iterator leftIter, rightIter;
19 aLhs.BeginReading(leftIter);
20 aRhs.BeginReading(rightIter);
22 size_type lLength = leftIter.size_forward();
23 size_type rLength = rightIter.size_forward();
24 size_type lengthToCompare = XPCOM_MIN(lLength, rLength);
26 int result;
27 if ((result = comp(leftIter.get(), rightIter.get(),
28 lengthToCompare, lengthToCompare)) == 0) {
29 if (lLength < rLength) {
30 result = -1;
31 } else if (rLength < lLength) {
32 result = 1;
33 } else {
34 result = 0;
38 return result;
41 int
42 nsTDefaultStringComparator_CharT::operator()(const char_type* aLhs,
43 const char_type* aRhs,
44 uint32_t aLLength,
45 uint32_t aRLength) const
47 return
48 aLLength == aRLength ? nsCharTraits<CharT>::compare(aLhs, aRhs, aLLength) :
49 (aLLength > aRLength) ? 1 : -1;