LCOV - code coverage report
Current view: top level - usr/local/src/libreoffice/sw/inc - stringhash.hxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 28 30 93.3 %
Date: 2013-07-09 Functions: 4 5 80.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2             : /*
       3             :  * This file is part of the LibreOffice project.
       4             :  *
       5             :  * This Source Code Form is subject to the terms of the Mozilla Public
       6             :  * License, v. 2.0. If a copy of the MPL was not distributed with this
       7             :  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
       8             :  *
       9             :  * This file incorporates work covered by the following license notice:
      10             :  *
      11             :  *   Licensed to the Apache Software Foundation (ASF) under one or more
      12             :  *   contributor license agreements. See the NOTICE file distributed
      13             :  *   with this work for additional information regarding copyright
      14             :  *   ownership. The ASF licenses this file to you under the Apache
      15             :  *   License, Version 2.0 (the "License"); you may not use this file
      16             :  *   except in compliance with the License. You may obtain a copy of
      17             :  *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
      18             :  */
      19             : #ifndef _STRINGHASH_HXX
      20             : #define _STRINGHASH_HXX
      21             : 
      22             : #include <tools/string.hxx>
      23             : 
      24             : struct StringEq
      25             : {
      26      309564 :     sal_Bool operator() ( const String *r1,
      27             :                             const String *r2) const
      28             :     {
      29      309564 :         return r1->Equals(*r2);
      30             :     }
      31             : };
      32             : 
      33             : struct StringEqRef
      34             : {
      35           0 :     sal_Bool operator() (const String &r1, const String &r2) const
      36             :     {
      37           0 :         return r1.Equals(r2);
      38             :     }
      39             : };
      40             : 
      41             : struct StringHash
      42             : {
      43      334666 :     size_t operator() ( const String *rString) const
      44             :     {
      45             :         sal_Int32 h, nLen;
      46      334666 :         h = nLen = rString->Len();
      47      334666 :         const sal_Unicode *pStr = rString->GetBuffer();
      48             : 
      49      334666 :         if ( nLen < 16 )
      50     3232908 :             while ( nLen-- > 0 )
      51     2675454 :                 h = (h*37) + *(pStr++);
      52             :         else
      53             :         {
      54             :             sal_Int32               nSkip;
      55       55939 :             const sal_Unicode* pEndStr = pStr+nLen-5;
      56             : 
      57             :             /* only sample some characters */
      58             :             /* the first 3, some characters between, and the last 5 */
      59       55939 :             h = (h*39) + *(pStr++);
      60       55939 :             h = (h*39) + *(pStr++);
      61       55939 :             h = (h*39) + *(pStr++);
      62             : 
      63       55939 :             nSkip = nLen / nLen < 32 ? 4 : 8;
      64       55939 :             nLen -= 8;
      65      289840 :             while ( nLen > 0 )
      66             :             {
      67      177962 :                 h = (h*39) + ( *pStr );
      68      177962 :                 pStr += nSkip;
      69      177962 :                 nLen -= nSkip;
      70             :             }
      71             : 
      72       55939 :             h = (h*39) + *(pEndStr++);
      73       55939 :             h = (h*39) + *(pEndStr++);
      74       55939 :             h = (h*39) + *(pEndStr++);
      75       55939 :             h = (h*39) + *(pEndStr++);
      76       55939 :             h = (h*39) + *(pEndStr++);
      77             :         }
      78      334666 :         return h;
      79             :     }
      80             : 
      81       32845 :     size_t operator() (const String & rStr) const
      82             :     {
      83       32845 :         return (*this)(&rStr);
      84             :     }
      85             : };
      86             : 
      87             : struct StringHashRef
      88             : {
      89        1581 :     size_t operator () (const String &rStr) const
      90             :     {
      91             :         StringHash aStrHash;
      92             : 
      93        1581 :         return aStrHash(&rStr);
      94             :     }
      95             : };
      96             : #endif // _STRINGHASH_HXX
      97             : 
      98             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10