[Libreoffice-commits] core.git: xmlhelp/source

Noel Grandin noel.grandin at collabora.co.uk
Thu Jun 1 10:56:58 UTC 2017


 xmlhelp/source/cxxhelp/provider/databases.cxx    |   19 ++--------
 xmlhelp/source/cxxhelp/provider/databases.hxx    |    6 +--
 xmlhelp/source/cxxhelp/provider/urlparameter.cxx |   40 ++++++++---------------
 3 files changed, 21 insertions(+), 44 deletions(-)

New commits:
commit 88ff39aee58cf0c098a2cce311cf62efbd76bb6d
Author: Noel Grandin <noel.grandin at collabora.co.uk>
Date:   Thu Jun 1 11:32:56 2017 +0200

    use OStringBuffer instead of manual buffer management
    
    Change-Id: Iba155637cbbdfc5d6b3a427372695d4d03319621
    Reviewed-on: https://gerrit.libreoffice.org/38297
    Tested-by: Jenkins <ci at libreoffice.org>
    Reviewed-by: Noel Grandin <noel.grandin at collabora.co.uk>

diff --git a/xmlhelp/source/cxxhelp/provider/databases.cxx b/xmlhelp/source/cxxhelp/provider/databases.cxx
index 6f8ed43c5205..cbabe0890bed 100644
--- a/xmlhelp/source/cxxhelp/provider/databases.cxx
+++ b/xmlhelp/source/cxxhelp/provider/databases.cxx
@@ -952,8 +952,7 @@ void Databases::changeCSS(const OUString& newStyleSheet)
 }
 
 void Databases::cascadingStylesheet( const OUString& Language,
-                                     std::unique_ptr<char[]>& buffer,
-                                     int* byteCount )
+                                     OStringBuffer& buffer )
 {
     if( ! m_pCustomCSSDoc )
     {
@@ -1056,18 +1055,13 @@ void Databases::cascadingStylesheet( const OUString& Language,
         }
     }
 
-    *byteCount = m_nCustomCSSDocLength;
-    buffer.reset( new char[ 1 + *byteCount ] );
-    buffer[*byteCount] = 0;
-    memcpy( buffer.get(), m_pCustomCSSDoc, m_nCustomCSSDocLength );
-
+    buffer.append( m_pCustomCSSDoc, m_nCustomCSSDocLength );
 }
 
 void Databases::setActiveText( const OUString& Module,
                                const OUString& Language,
                                const OUString& Id,
-                               std::unique_ptr<char[]>& buffer,
-                               int* byteCount )
+                               OStringBuffer& buffer )
 {
     DataBaseIterator aDbIt( m_xContext, *this, Module, Language, true );
 
@@ -1110,15 +1104,10 @@ void Databases::setActiveText( const OUString& Module,
                 break;
             }
 
-        *byteCount = nSize;
-        buffer.reset( new char[ 1 + nSize ] );
-        buffer[nSize] = 0;
-        memcpy( buffer.get(), pData, nSize );
+        buffer.append( pData, nSize );
     }
     else
     {
-        *byteCount = 0;
-        buffer.reset( new char[1] ); // Initialize with 1 to avoid compiler warnings
         if( !bFoundAsEmpty )
             m_aEmptyActiveTextSet.insert( id );
     }
diff --git a/xmlhelp/source/cxxhelp/provider/databases.hxx b/xmlhelp/source/cxxhelp/provider/databases.hxx
index 2b5975119e12..862faa5c7b29 100644
--- a/xmlhelp/source/cxxhelp/provider/databases.hxx
+++ b/xmlhelp/source/cxxhelp/provider/databases.hxx
@@ -173,8 +173,7 @@ namespace chelp {
          */
 
         void cascadingStylesheet( const OUString& Language,
-                                  std::unique_ptr<char[]>& buffer,
-                                  int* byteCount );
+                                  OStringBuffer& buffer );
 
         /**
          *  Changes the stylesheet for further reads.
@@ -189,8 +188,7 @@ namespace chelp {
         void setActiveText( const OUString& Module,
                             const OUString& Language,
                             const OUString& Id,
-                            std::unique_ptr<char[]>& buffer,
-                            int* byteCount );
+                            OStringBuffer& buffer );
 
         /**
          *  Has the purpose of forcing the jarfile to stay open
diff --git a/xmlhelp/source/cxxhelp/provider/urlparameter.cxx b/xmlhelp/source/cxxhelp/provider/urlparameter.cxx
index 334029d48633..8c2f0067e8fa 100644
--- a/xmlhelp/source/cxxhelp/provider/urlparameter.cxx
+++ b/xmlhelp/source/cxxhelp/provider/urlparameter.cxx
@@ -327,16 +327,14 @@ public:
 
     void addToBuffer( const char* buffer,int len );
 
-    sal_Int8 const * getData() const { return reinterpret_cast<sal_Int8 const *>(buffer.get()); }
-
-    sal_Int32 getLen() const { return sal_Int32( len ); }
+    OStringBuffer const & getData() const { return buffer; }
 
 private:
 
     osl::Mutex m_aMutex;
 
-    int len,pos;
-    std::unique_ptr<char[]> buffer;
+    int pos;
+    OStringBuffer buffer;
 };
 
 
@@ -356,7 +354,7 @@ void URLParameter::open( const Command& aCommand,
     InputStreamTransformer* p = new InputStreamTransformer( this,m_pDatabases,isRoot() );
     try
     {
-        xDataSink->writeBytes( Sequence< sal_Int8 >( p->getData(),p->getLen() ) );
+        xDataSink->writeBytes( Sequence< sal_Int8 >( reinterpret_cast<const sal_Int8*>(p->getData().getStr()), p->getData().getLength() ) );
     }
     catch( const Exception& )
     {
@@ -716,25 +714,21 @@ fileClose(void * context) {
 InputStreamTransformer::InputStreamTransformer( URLParameter* urlParam,
                                                 Databases*    pDatabases,
                                                 bool isRoot )
-    : len( 0 ),
-      pos( 0 ),
-      buffer( new char[1] ) // Initializing with one element to avoid gcc compiler warning
+    : pos( 0 )
 {
     if( isRoot )
     {
-        buffer.reset();
+        buffer.setLength(0);
         pDatabases->cascadingStylesheet( urlParam->get_language(),
-                                         buffer,
-                                         &len );
+                                         buffer );
     }
     else if( urlParam->isActive() )
     {
-        buffer.reset();
+        buffer.setLength(0);
         pDatabases->setActiveText( urlParam->get_module(),
                                    urlParam->get_language(),
                                    urlParam->get_id(),
-                                   buffer,
-                                   &len );
+                                   buffer );
     }
     else
     {
@@ -918,7 +912,7 @@ sal_Int32 SAL_CALL InputStreamTransformer::readBytes( Sequence< sal_Int8 >& aDat
 {
     osl::MutexGuard aGuard( m_aMutex );
 
-    int curr,available_ = len-pos;
+    int curr,available_ = buffer.getLength() - pos;
     if( nBytesToRead <= available_ )
         curr = nBytesToRead;
     else
@@ -950,7 +944,7 @@ void SAL_CALL InputStreamTransformer::skipBytes( sal_Int32 nBytesToSkip )
 sal_Int32 SAL_CALL InputStreamTransformer::available()
 {
     osl::MutexGuard aGuard( m_aMutex );
-    return len-pos > 0 ? len - pos : 0 ;
+    return buffer.getLength() - pos > 0 ? buffer.getLength() - pos : 0 ;
 }
 
 
@@ -967,8 +961,8 @@ void SAL_CALL InputStreamTransformer::seek( sal_Int64 location )
     else
         pos = sal::static_int_cast<sal_Int32>( location );
 
-    if( pos > len )
-        pos = len;
+    if( pos > buffer.getLength() )
+        pos = buffer.getLength();
 }
 
 
@@ -983,7 +977,7 @@ sal_Int64 SAL_CALL InputStreamTransformer::getLength()
 {
     osl::MutexGuard aGuard( m_aMutex );
 
-    return len;
+    return buffer.getLength();
 }
 
 
@@ -991,11 +985,7 @@ void InputStreamTransformer::addToBuffer( const char* buffer_,int len_ )
 {
     osl::MutexGuard aGuard( m_aMutex );
 
-    std::unique_ptr<char[]> tmp(buffer.release());
-    buffer.reset( new char[ len+len_ ] );
-    memcpy( static_cast<void*>(buffer.get()),static_cast<void*>(tmp.get()),sal_uInt32( len ) );
-    memcpy( static_cast<void*>(buffer.get()+len),static_cast<void const *>(buffer_),sal_uInt32( len_ ) );
-    len += len_;
+    buffer.append( buffer_, len_ );
 }
 
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */


More information about the Libreoffice-commits mailing list