LCOV - code coverage report
Current view: top level - xpcom/string - nsTStringComparator.cpp (source / functions) Hit Total Coverage
Test: output.info Lines: 19 20 95.0 %
Date: 2017-07-14 16:53:18 Functions: 4 4 100.0 %
Legend: Lines: hit not hit

          Line data    Source code
       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/. */
       6             : 
       7             : int NS_FASTCALL
       8        2009 : Compare(const nsTSubstring_CharT::base_string_type& aLhs,
       9             :         const nsTSubstring_CharT::base_string_type& aRhs,
      10             :         const nsTStringComparator_CharT& comp)
      11             : {
      12             :   typedef nsTSubstring_CharT::size_type size_type;
      13             : 
      14        2009 :   if (&aLhs == &aRhs) {
      15           0 :     return 0;
      16             :   }
      17             : 
      18        2009 :   nsTSubstring_CharT::const_iterator leftIter, rightIter;
      19        2009 :   aLhs.BeginReading(leftIter);
      20        2009 :   aRhs.BeginReading(rightIter);
      21             : 
      22        2009 :   size_type lLength = aLhs.Length();
      23        2009 :   size_type rLength = aRhs.Length();
      24        2009 :   size_type lengthToCompare = XPCOM_MIN(lLength, rLength);
      25             : 
      26             :   int result;
      27        2009 :   if ((result = comp(leftIter.get(), rightIter.get(),
      28        2009 :                      lengthToCompare, lengthToCompare)) == 0) {
      29         411 :     if (lLength < rLength) {
      30          33 :       result = -1;
      31         378 :     } else if (rLength < lLength) {
      32           2 :       result = 1;
      33             :     } else {
      34         376 :       result = 0;
      35             :     }
      36             :   }
      37             : 
      38        2009 :   return result;
      39             : }
      40             : 
      41             : int
      42        5007 : nsTDefaultStringComparator_CharT::operator()(const char_type* aLhs,
      43             :                                              const char_type* aRhs,
      44             :                                              uint32_t aLLength,
      45             :                                              uint32_t aRLength) const
      46             : {
      47             :   return
      48        5007 :     aLLength == aRLength ? nsCharTraits<CharT>::compare(aLhs, aRhs, aLLength) :
      49        5007 :                             (aLLength > aRLength) ? 1 : -1;
      50             : }

Generated by: LCOV version 1.13