LCOV - code coverage report
Current view: top level - libreoffice/sw/inc - stringhash.hxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 28 30 93.3 %
Date: 2012-12-27 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       37684 :     sal_Bool operator() ( const String *r1,
      27             :                             const String *r2) const
      28             :     {
      29       37684 :         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       64765 :     size_t operator() ( const String *rString) const
      44             :     {
      45             :         sal_Int32 h, nLen;
      46       64765 :         h = nLen = rString->Len();
      47       64765 :         const sal_Unicode *pStr = rString->GetBuffer();
      48             : 
      49       64765 :         if ( nLen < 16 )
      50      585755 :             while ( nLen-- > 0 )
      51      479061 :                 h = (h*37) + *(pStr++);
      52             :         else
      53             :         {
      54             :             sal_Int32               nSkip;
      55       11418 :             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       11418 :             h = (h*39) + *(pStr++);
      60       11418 :             h = (h*39) + *(pStr++);
      61       11418 :             h = (h*39) + *(pStr++);
      62             : 
      63       11418 :             nSkip = nLen / nLen < 32 ? 4 : 8;
      64       11418 :             nLen -= 8;
      65       61850 :             while ( nLen > 0 )
      66             :             {
      67       39014 :                 h = (h*39) + ( *pStr );
      68       39014 :                 pStr += nSkip;
      69       39014 :                 nLen -= nSkip;
      70             :             }
      71             : 
      72       11418 :             h = (h*39) + *(pEndStr++);
      73       11418 :             h = (h*39) + *(pEndStr++);
      74       11418 :             h = (h*39) + *(pEndStr++);
      75       11418 :             h = (h*39) + *(pEndStr++);
      76       11418 :             h = (h*39) + *(pEndStr++);
      77             :         }
      78       64765 :         return h;
      79             :     }
      80             : 
      81       19479 :     size_t operator() (const String & rStr) const
      82             :     {
      83       19479 :         return (*this)(&rStr);
      84             :     }
      85             : };
      86             : 
      87             : struct StringHashRef
      88             : {
      89         540 :     size_t operator () (const String &rStr) const
      90             :     {
      91             :         StringHash aStrHash;
      92             : 
      93         540 :         return aStrHash(&rStr);
      94             :     }
      95             : };
      96             : #endif // _STRINGHASH_HXX
      97             : 
      98             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10