LCOV - code coverage report
Current view: top level - sal/rtl/source - byteseq.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 76 88 86.4 %
Date: 2012-08-25 Functions: 9 11 81.8 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 31 45 68.9 %

           Branch data     Line data    Source code
       1                 :            : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2                 :            : /*************************************************************************
       3                 :            :  *
       4                 :            :  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
       5                 :            :  *
       6                 :            :  * Copyright 2000, 2010 Oracle and/or its affiliates.
       7                 :            :  *
       8                 :            :  * OpenOffice.org - a multi-platform office productivity suite
       9                 :            :  *
      10                 :            :  * This file is part of OpenOffice.org.
      11                 :            :  *
      12                 :            :  * OpenOffice.org is free software: you can redistribute it and/or modify
      13                 :            :  * it under the terms of the GNU Lesser General Public License version 3
      14                 :            :  * only, as published by the Free Software Foundation.
      15                 :            :  *
      16                 :            :  * OpenOffice.org is distributed in the hope that it will be useful,
      17                 :            :  * but WITHOUT ANY WARRANTY; without even the implied warranty of
      18                 :            :  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
      19                 :            :  * GNU Lesser General Public License version 3 for more details
      20                 :            :  * (a copy is included in the LICENSE file that accompanied this code).
      21                 :            :  *
      22                 :            :  * You should have received a copy of the GNU Lesser General Public License
      23                 :            :  * version 3 along with OpenOffice.org.  If not, see
      24                 :            :  * <http://www.openoffice.org/license.html>
      25                 :            :  * for a copy of the LGPLv3 License.
      26                 :            :  *
      27                 :            :  ************************************************************************/
      28                 :            : 
      29                 :            : #include <string.h>
      30                 :            : 
      31                 :            : #include <osl/diagnose.h>
      32                 :            : #include <osl/interlck.h>
      33                 :            : 
      34                 :            : #include <rtl/byteseq.h>
      35                 :            : #include <rtl/alloc.h>
      36                 :            : #include <rtl/memory.h>
      37                 :            : 
      38                 :            : /* static data to be referenced by all empty strings
      39                 :            :  * the refCount is predefined to 1 and must never become 0 !
      40                 :            :  */
      41                 :            : static sal_Sequence aEmpty_rtl_ByteSeq =
      42                 :            : {
      43                 :            :     1,      /* sal_Int32    refCount;   */
      44                 :            :     0,      /* sal_Int32    length;     */
      45                 :            :     { 0 }   /* sal_Unicode  buffer[1];  */
      46                 :            : };
      47                 :            : 
      48                 :            : //==================================================================================================
      49                 :      21121 : void SAL_CALL rtl_byte_sequence_reference2One(
      50                 :            :     sal_Sequence ** ppSequence ) SAL_THROW_EXTERN_C()
      51                 :            : {
      52                 :            :     sal_Sequence * pSequence, * pNew;
      53                 :            :     sal_Int32 nElements;
      54                 :            : 
      55                 :            :     OSL_ENSURE( ppSequence, "### null ptr!" );
      56                 :      21121 :     pSequence = *ppSequence;
      57                 :            : 
      58         [ +  + ]:      21121 :     if (pSequence->nRefCount > 1)
      59                 :            :     {
      60                 :          5 :         nElements = pSequence->nElements;
      61         [ +  - ]:          5 :         if (nElements)
      62                 :            :         {
      63                 :          5 :             pNew = (sal_Sequence *)rtl_allocateMemory( SAL_SEQUENCE_HEADER_SIZE + nElements );
      64                 :            : 
      65         [ +  - ]:          5 :             if ( pNew != 0 )
      66                 :          5 :                 memcpy( pNew->elements, pSequence->elements, nElements );
      67                 :            : 
      68         [ -  + ]:          5 :             if (! osl_decrementInterlockedCount( &pSequence->nRefCount ))
      69                 :          0 :                 rtl_freeMemory( pSequence );
      70                 :            :         }
      71                 :            :         else
      72                 :            :         {
      73                 :          0 :             pNew = (sal_Sequence *)rtl_allocateMemory( SAL_SEQUENCE_HEADER_SIZE );
      74                 :            :         }
      75                 :            : 
      76         [ +  - ]:          5 :         if ( pNew != 0 )
      77                 :            :         {
      78                 :          5 :             pNew->nRefCount = 1;
      79                 :          5 :             pNew->nElements = nElements;
      80                 :            :         }
      81                 :            : 
      82                 :          5 :         *ppSequence = pNew;
      83                 :            :     }
      84                 :      21121 : }
      85                 :            : 
      86                 :            : //==================================================================================================
      87                 :      49487 : void SAL_CALL rtl_byte_sequence_realloc(
      88                 :            :     sal_Sequence ** ppSequence, sal_Int32 nSize ) SAL_THROW_EXTERN_C()
      89                 :            : {
      90                 :            :     sal_Sequence * pSequence, * pNew;
      91                 :            :     sal_Int32 nElements;
      92                 :            : 
      93                 :            :     OSL_ENSURE( ppSequence, "### null ptr!" );
      94                 :      49487 :     pSequence = *ppSequence;
      95                 :      49487 :     nElements = pSequence->nElements;
      96                 :            : 
      97         [ -  + ]:      49487 :     if (nElements == nSize)
      98                 :      49487 :         return;
      99                 :            : 
     100         [ +  + ]:      49487 :     if (pSequence->nRefCount > 1) // split
     101                 :            :     {
     102                 :       7991 :         pNew = (sal_Sequence *)rtl_allocateMemory( SAL_SEQUENCE_HEADER_SIZE + nSize );
     103                 :            : 
     104         [ +  - ]:       7991 :         if ( pNew != 0 )
     105                 :            :         {
     106         [ +  - ]:       7991 :             if (nSize > nElements)
     107                 :            :             {
     108                 :       7991 :                 memcpy( pNew->elements, pSequence->elements, nElements );
     109                 :       7991 :                 memset( pNew->elements + nElements, 0, nSize - nElements );
     110                 :            :             }
     111                 :            :             else
     112                 :            :             {
     113                 :          0 :                 memcpy( pNew->elements, pSequence->elements, nSize );
     114                 :            :             }
     115                 :            :         }
     116                 :            : 
     117         [ -  + ]:       7991 :         if (! osl_decrementInterlockedCount( &pSequence->nRefCount ))
     118                 :          0 :             rtl_freeMemory( pSequence );
     119                 :       7991 :         pSequence = pNew;
     120                 :            :     }
     121                 :            :     else
     122                 :            :     {
     123                 :            :         pSequence = (sal_Sequence *)rtl_reallocateMemory(
     124                 :      41496 :             pSequence, SAL_SEQUENCE_HEADER_SIZE + nSize );
     125                 :            :     }
     126                 :            : 
     127         [ +  - ]:      49487 :     if ( pSequence != 0 )
     128                 :            :     {
     129                 :      49487 :         pSequence->nRefCount = 1;
     130                 :      49487 :         pSequence->nElements = nSize;
     131                 :            :     }
     132                 :            : 
     133                 :      49487 :     *ppSequence = pSequence;
     134                 :            : }
     135                 :            : 
     136                 :            : //==================================================================================================
     137                 :    4612810 : void SAL_CALL rtl_byte_sequence_acquire( sal_Sequence *pSequence )
     138                 :            :     SAL_THROW_EXTERN_C()
     139                 :            : {
     140                 :            :     OSL_ASSERT( pSequence );
     141                 :    4612810 :     osl_incrementInterlockedCount( &(pSequence->nRefCount) );
     142                 :    4612806 : }
     143                 :            : 
     144                 :            : //==================================================================================================
     145                 :    4629992 : void SAL_CALL rtl_byte_sequence_release( sal_Sequence *pSequence )
     146                 :            :     SAL_THROW_EXTERN_C()
     147                 :            : {
     148            [ + ]:    4629992 :     if ( pSequence != 0 )
     149                 :            :     {
     150         [ +  + ]:    4630029 :         if (! osl_decrementInterlockedCount( &(pSequence->nRefCount )) )
     151                 :            :         {
     152                 :      19046 :             rtl_freeMemory( pSequence );
     153                 :            :         }
     154                 :            :     }
     155                 :    4629997 : }
     156                 :            : 
     157                 :            : //==================================================================================================
     158                 :     449857 : void SAL_CALL rtl_byte_sequence_construct( sal_Sequence **ppSequence , sal_Int32 nLength )
     159                 :            :     SAL_THROW_EXTERN_C()
     160                 :            : {
     161                 :            :     OSL_ASSERT( ppSequence );
     162         [ -  + ]:     449857 :     if( *ppSequence )
     163                 :            :     {
     164                 :          0 :         rtl_byte_sequence_release( *ppSequence );
     165                 :          0 :         *ppSequence = 0;
     166                 :            :     }
     167                 :            : 
     168         [ +  + ]:     449857 :     if( nLength )
     169                 :            :     {
     170                 :        198 :         *ppSequence = (sal_Sequence *) rtl_allocateZeroMemory( SAL_SEQUENCE_HEADER_SIZE + nLength );
     171                 :            : 
     172         [ +  - ]:        198 :         if ( *ppSequence != 0 )
     173                 :            :         {
     174                 :        198 :             (*ppSequence)->nRefCount = 1;
     175                 :        198 :             (*ppSequence)->nElements = nLength;
     176                 :            :         }
     177                 :            :     }
     178                 :            :     else
     179                 :            :     {
     180                 :     449659 :         *ppSequence = &aEmpty_rtl_ByteSeq;
     181                 :     449659 :         rtl_byte_sequence_acquire( *ppSequence );
     182                 :            :     }
     183                 :     449857 : }
     184                 :            : 
     185                 :            : //==================================================================================================
     186                 :      21901 : void SAL_CALL rtl_byte_sequence_constructNoDefault( sal_Sequence **ppSequence , sal_Int32 nLength )
     187                 :            :     SAL_THROW_EXTERN_C()
     188                 :            : {
     189                 :            :     OSL_ASSERT( ppSequence );
     190         [ -  + ]:      21901 :     if( *ppSequence )
     191                 :            :     {
     192                 :          0 :         rtl_byte_sequence_release( *ppSequence );
     193                 :          0 :         *ppSequence = 0;
     194                 :            :     }
     195                 :            : 
     196                 :      21901 :     *ppSequence = (sal_Sequence *) rtl_allocateMemory( SAL_SEQUENCE_HEADER_SIZE + nLength );
     197                 :            : 
     198         [ +  - ]:      21901 :     if ( *ppSequence != 0 )
     199                 :            :     {
     200                 :      21901 :         (*ppSequence)->nRefCount = 1;
     201                 :      21901 :         (*ppSequence)->nElements = nLength;
     202                 :            :     }
     203                 :      21901 : }
     204                 :            : 
     205                 :            : //==================================================================================================
     206                 :      18702 : void SAL_CALL rtl_byte_sequence_constructFromArray(
     207                 :            :     sal_Sequence **ppSequence, const sal_Int8 *pData , sal_Int32 nLength )
     208                 :            :     SAL_THROW_EXTERN_C()
     209                 :            : {
     210                 :      18702 :     rtl_byte_sequence_constructNoDefault( ppSequence , nLength );
     211         [ +  - ]:      18702 :     if ( *ppSequence != 0 )
     212                 :      18702 :         memcpy( (*ppSequence)->elements, pData, nLength );
     213                 :      18702 : }
     214                 :            : 
     215                 :            : //==================================================================================================
     216                 :    4520738 : void SAL_CALL rtl_byte_sequence_assign( sal_Sequence **ppSequence , sal_Sequence *pSequence )
     217                 :            :     SAL_THROW_EXTERN_C()
     218                 :            : {
     219         [ +  + ]:    4520738 :     if ( *ppSequence != pSequence)
     220                 :            :     {
     221         [ +  + ]:    3498662 :         if( *ppSequence )
     222                 :            :         {
     223                 :    1076197 :             rtl_byte_sequence_release( *ppSequence );
     224                 :            :         }
     225                 :    3498665 :         *ppSequence = pSequence;
     226                 :    3498665 :         rtl_byte_sequence_acquire( *ppSequence );
     227                 :            :     }
     228                 :            : //  else
     229                 :            : //      nothing to do
     230                 :            : 
     231                 :    4520742 : }
     232                 :            : 
     233                 :            : //==================================================================================================
     234                 :    1333586 : sal_Bool SAL_CALL rtl_byte_sequence_equals( sal_Sequence *pSequence1 , sal_Sequence *pSequence2 )
     235                 :            :     SAL_THROW_EXTERN_C()
     236                 :            : {
     237                 :            :     OSL_ASSERT( pSequence1 );
     238                 :            :     OSL_ASSERT( pSequence2 );
     239         [ +  + ]:    1333586 :     if (pSequence1 == pSequence2)
     240                 :            :     {
     241                 :    1192912 :         return sal_True;
     242                 :            :     }
     243         [ +  + ]:     140674 :     if (pSequence1->nElements != pSequence2->nElements)
     244                 :            :     {
     245                 :      49945 :         return sal_False;
     246                 :            :     }
     247                 :            :     return (sal_Bool)
     248                 :            :         (rtl_compareMemory(
     249                 :      90729 :             pSequence1->elements, pSequence2->elements, pSequence1->nElements )
     250                 :    1333586 :          == 0);
     251                 :            : }
     252                 :            : 
     253                 :            : 
     254                 :            : //==================================================================================================
     255                 :          0 : const sal_Int8 *SAL_CALL rtl_byte_sequence_getConstArray( sal_Sequence *pSequence )
     256                 :            :     SAL_THROW_EXTERN_C()
     257                 :            : {
     258                 :          0 :     return ((const sal_Int8*)(pSequence->elements));
     259                 :            : }
     260                 :            : 
     261                 :            : //==================================================================================================
     262                 :          0 : sal_Int32 SAL_CALL rtl_byte_sequence_getLength( sal_Sequence *pSequence )
     263                 :            :     SAL_THROW_EXTERN_C()
     264                 :            : {
     265                 :          0 :     return pSequence->nElements;
     266                 :            : }
     267                 :            : 
     268                 :            : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10