LCOV - code coverage report
Current view: top level - sw/inc - stringhash.hxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 28 30 93.3 %
Date: 2012-08-25 Functions: 4 5 80.0 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 7 8 87.5 %

           Branch data     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                 :     102474 :     sal_Bool operator() ( const String *r1,
      27                 :            :                             const String *r2) const
      28                 :            :     {
      29                 :     102474 :         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                 :     252597 :     size_t operator() ( const String *rString) const
      44                 :            :     {
      45                 :            :         sal_Int32 h, nLen;
      46                 :     252597 :         h = nLen = rString->Len();
      47                 :     252597 :         const sal_Unicode *pStr = rString->GetBuffer();
      48                 :            : 
      49         [ +  + ]:     252597 :         if ( nLen < 16 )
      50         [ +  + ]:    2164647 :             while ( nLen-- > 0 )
      51                 :    1937117 :                 h = (h*37) + *(pStr++);
      52                 :            :         else
      53                 :            :         {
      54                 :            :             sal_Int32               nSkip;
      55                 :      25067 :             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                 :      25067 :             h = (h*39) + *(pStr++);
      60                 :      25067 :             h = (h*39) + *(pStr++);
      61                 :      25067 :             h = (h*39) + *(pStr++);
      62                 :            : 
      63         [ +  - ]:      25067 :             nSkip = nLen / nLen < 32 ? 4 : 8;
      64                 :      25067 :             nLen -= 8;
      65         [ +  + ]:     107013 :             while ( nLen > 0 )
      66                 :            :             {
      67                 :      81946 :                 h = (h*39) + ( *pStr );
      68                 :      81946 :                 pStr += nSkip;
      69                 :      81946 :                 nLen -= nSkip;
      70                 :            :             }
      71                 :            : 
      72                 :      25067 :             h = (h*39) + *(pEndStr++);
      73                 :      25067 :             h = (h*39) + *(pEndStr++);
      74                 :      25067 :             h = (h*39) + *(pEndStr++);
      75                 :      25067 :             h = (h*39) + *(pEndStr++);
      76                 :      25067 :             h = (h*39) + *(pEndStr++);
      77                 :            :         }
      78                 :     252597 :         return h;
      79                 :            :     }
      80                 :            : 
      81                 :      62888 :     size_t operator() (const String & rStr) const
      82                 :            :     {
      83                 :      62888 :         return (*this)(&rStr);
      84                 :            :     }
      85                 :            : };
      86                 :            : 
      87                 :            : struct StringHashRef
      88                 :            : {
      89                 :       1764 :     size_t operator () (const String &rStr) const
      90                 :            :     {
      91                 :            :         StringHash aStrHash;
      92                 :            : 
      93                 :       1764 :         return aStrHash(&rStr);
      94                 :            :     }
      95                 :            : };
      96                 :            : #endif // _STRINGHASH_HXX
      97                 :            : 
      98                 :            : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10