[Libreoffice-commits] core.git: 2 commits - connectivity/source sw/source

Wol anthony at youngman.org.uk
Mon Apr 29 01:20:44 PDT 2013


 connectivity/source/drivers/postgresql/pq_connection.cxx |   59 ++++++---------
 sw/source/core/text/inftxt.cxx                           |    8 +-
 sw/source/core/text/inftxt.hxx                           |    4 -
 sw/source/core/text/itrcrsr.cxx                          |    4 -
 sw/source/core/text/porglue.cxx                          |    8 +-
 sw/source/core/text/txttab.cxx                           |    2 
 6 files changed, 38 insertions(+), 47 deletions(-)

New commits:
commit 8ad743ca8d45e094e433627cf0cf70d11a56084e
Author: Wol <anthony at youngman.org.uk>
Date:   Tue Apr 16 13:30:30 2013 +0100

    pgsql-sdbc: conninfo keywords as static table instead of series of "else if"
    
    New keywords can now simply be added to a static array rather than
    adding a new "else if" blocks for each keyword.
    
    Change-Id: Ib581b3e834a57e0dfa9d139bcb4ae7a0a52a5472

diff --git a/connectivity/source/drivers/postgresql/pq_connection.cxx b/connectivity/source/drivers/postgresql/pq_connection.cxx
index 4bc15e4..4f830a1 100644
--- a/connectivity/source/drivers/postgresql/pq_connection.cxx
+++ b/connectivity/source/drivers/postgresql/pq_connection.cxx
@@ -482,44 +482,30 @@ static void properties2arrays( const Sequence< PropertyValue > & args,
     // I.e. they are prefiltered to have only relevant ones?
     // Else, at least support all keywords from
     // http://www.postgresql.org/docs/9.0/interactive/libpq-connect.html
+
+    static const char* keyword_list[] = {
+        "password",
+        "user",
+        "port",
+        "dbname",
+        "connect_timeout",
+        "options",
+        "requiressl"
+    };
+
     for( int i = 0; i < args.getLength() ; ++i )
     {
-        bool append = true;
-        // TODO: rewrite this as a static table of keywords, and a loop over these keywords.
-        if( args[i].Name.matchIgnoreAsciiCaseAsciiL( RTL_CONSTASCII_STRINGPARAM( "password" ) ) )
-        {
-            keywords.push_back( "password", SAL_NO_ACQUIRE );
-        }
-        else if( args[i].Name.matchIgnoreAsciiCaseAsciiL( RTL_CONSTASCII_STRINGPARAM( "user" ) ) )
-        {
-            keywords.push_back( "user", SAL_NO_ACQUIRE );
-        }
-        else if( args[i].Name.matchIgnoreAsciiCaseAsciiL( RTL_CONSTASCII_STRINGPARAM( "port" ) ) )
-        {
-            keywords.push_back( "port", SAL_NO_ACQUIRE );
-        }
-        else if( args[i].Name.matchIgnoreAsciiCaseAsciiL( RTL_CONSTASCII_STRINGPARAM( "dbname" ) ) )
-        {
-            keywords.push_back( "dbname", SAL_NO_ACQUIRE );
-        }
-        else if( args[i].Name.matchIgnoreAsciiCaseAsciiL( RTL_CONSTASCII_STRINGPARAM( "connect_timeout" ) ) )
-        {
-            keywords.push_back( "connect_timeout", SAL_NO_ACQUIRE );
-        }
-        else if( args[i].Name.matchIgnoreAsciiCaseAsciiL( RTL_CONSTASCII_STRINGPARAM( "options" ) ) )
-        {
-            keywords.push_back( "options", SAL_NO_ACQUIRE );
-        }
-        else if( args[i].Name.matchIgnoreAsciiCaseAsciiL( RTL_CONSTASCII_STRINGPARAM( "requiressl" ) ) )
+        bool append = false;
+        for( size_t j = 0; j < SAL_N_ELEMENTS( keyword_list ); j++)
         {
-            keywords.push_back( "requiressl", SAL_NO_ACQUIRE );
-        }
-        else
-        {
-            append = false;
-            // ignore for now
-            OSL_TRACE("sdbc-postgresql: unknown argument '%s'", OUStringToOString( args[i].Name, RTL_TEXTENCODING_UTF8 ).getStr() );
+            if( args[i].Name.equalsIgnoreAsciiCaseAscii( keyword_list[j] ))
+            {
+                keywords.push_back( keyword_list[j], SAL_NO_ACQUIRE );
+                append = true;
+                break;
+            }
         }
+
         if( append )
         {
             OUString value;
@@ -527,6 +513,11 @@ static void properties2arrays( const Sequence< PropertyValue > & args,
             char *v = strdup(OUStringToOString(value, enc).getStr());
             values.push_back ( v );
         }
+        else
+        {
+            // ignore for now
+            OSL_TRACE("sdbc-postgresql: unknown argument '%s'", OUStringToOString( args[i].Name, RTL_TEXTENCODING_UTF8 ).getStr() );
+        }
     }
 }
 
commit 13a0477250793d1ab06329b244f26fffbebb0bab
Author: Miklos Vajna <vmiklos at suse.cz>
Date:   Mon Apr 29 10:02:24 2013 +0200

    SwTxtSizeInfo ctor: take a pointer, not a reference
    
    The ctor later will turn that reference to a pointer anyway, but the old
    code made it easy to pass a String, get it implicitly converted to
    OUString, and then we took the address of the temporary OUString, later
    resulting in accessing already freed memory. Instead, take an OUString
    pointer, and then the compiler will warn about a String* -> OUString*
    conversion. Adapt one remaining caller accordingly.
    
    Change-Id: I4084dea1d245f0c8919d6afe47c5f391729f6eaf

diff --git a/sw/source/core/text/inftxt.cxx b/sw/source/core/text/inftxt.cxx
index 5adc1c5..b1ac0f2 100644
--- a/sw/source/core/text/inftxt.cxx
+++ b/sw/source/core/text/inftxt.cxx
@@ -312,7 +312,7 @@ void SwTxtSizeInfo::CtorInitTxtSizeInfo( SwTxtFrm *pFrame, SwFont *pNewFnt,
     SetLen( GetMinLen( *this ) );
 }
 
-SwTxtSizeInfo::SwTxtSizeInfo( const SwTxtSizeInfo &rNew, const OUString &rTxt,
+SwTxtSizeInfo::SwTxtSizeInfo( const SwTxtSizeInfo &rNew, const OUString* pTxt_,
                               const sal_Int32 nIndex, const xub_StrLen nLength )
     : SwTxtInfo( rNew ),
       pKanaComp(((SwTxtSizeInfo&)rNew).GetpKanaComp()),
@@ -323,7 +323,7 @@ SwTxtSizeInfo::SwTxtSizeInfo( const SwTxtSizeInfo &rNew, const OUString &rTxt,
       pUnderFnt(((SwTxtSizeInfo&)rNew).GetUnderFnt()),
       pFrm( rNew.pFrm ),
       pOpt(&rNew.GetOpt()),
-      pTxt(&rTxt),
+      pTxt(pTxt_),
       nIdx(nIndex),
       nLen(nLength),
       nKanaIdx( rNew.GetKanaIdx() ),
@@ -474,8 +474,8 @@ void SwTxtPaintInfo::CtorInitTxtPaintInfo( SwTxtFrm *pFrame, const SwRect &rPain
 #endif
 }
 
-SwTxtPaintInfo::SwTxtPaintInfo( const SwTxtPaintInfo &rInf, const XubString &rTxt )
-    : SwTxtSizeInfo( rInf, rTxt ),
+SwTxtPaintInfo::SwTxtPaintInfo( const SwTxtPaintInfo &rInf, const OUString* pTxt_ )
+    : SwTxtSizeInfo( rInf, pTxt_ ),
       pWrongList( rInf.GetpWrongList() ),
       pGrammarCheckList( rInf.GetGrammarCheckList() ),
       pSmartTags( rInf.GetSmartTags() ),    // SMARTTAGS
diff --git a/sw/source/core/text/inftxt.hxx b/sw/source/core/text/inftxt.hxx
index e34aca8..2faee80 100644
--- a/sw/source/core/text/inftxt.hxx
+++ b/sw/source/core/text/inftxt.hxx
@@ -201,7 +201,7 @@ protected:
     SwTxtSizeInfo() : pKanaComp(0), pVsh(0), pOut(0), pRef(0), pFnt(0), pUnderFnt(0), pFrm(0), pOpt(0), pTxt(0) {}
 public:
     SwTxtSizeInfo( const SwTxtSizeInfo &rInf );
-    SwTxtSizeInfo( const SwTxtSizeInfo &rInf, const OUString &rTxt,
+    SwTxtSizeInfo( const SwTxtSizeInfo &rInf, const OUString* pTxt_,
                    const sal_Int32 nIdx = 0,
                    const xub_StrLen nLen = STRING_LEN );
 
@@ -400,7 +400,7 @@ protected:
 #endif
 public:
     SwTxtPaintInfo( const SwTxtPaintInfo &rInf );
-    SwTxtPaintInfo( const SwTxtPaintInfo &rInf, const XubString &rTxt );
+    SwTxtPaintInfo( const SwTxtPaintInfo &rInf, const OUString* pTxt );
 
     void CtorInitTxtPaintInfo( SwTxtFrm *pFrame, const SwRect &rPaint );
 
diff --git a/sw/source/core/text/itrcrsr.cxx b/sw/source/core/text/itrcrsr.cxx
index bb1d08b..3befea2 100644
--- a/sw/source/core/text/itrcrsr.cxx
+++ b/sw/source/core/text/itrcrsr.cxx
@@ -490,7 +490,7 @@ void SwTxtCursor::_GetCharRect( SwRect* pOrig, const xub_StrLen nOfst,
     SwCrsrMoveState* pCMS )
 {
     const OUString aText = GetInfo().GetTxt();
-    SwTxtSizeInfo aInf( GetInfo(), aText, nStart );
+    SwTxtSizeInfo aInf( GetInfo(), &aText, nStart );
     if( GetPropFont() )
         aInf.GetFont()->SetProportion( GetPropFont() );
     KSHORT nTmpAscent, nTmpHeight;  // Zeilenhoehe
@@ -1594,7 +1594,7 @@ xub_StrLen SwTxtCursor::GetCrsrOfst( SwPosition *pPos, const Point &rPoint,
                 nOldProp = 0;
             {
                 OUString aText = rText;
-                SwTxtSizeInfo aSizeInf( GetInfo(), aText, nCurrStart );
+                SwTxtSizeInfo aSizeInf( GetInfo(), &aText, nCurrStart );
                 ((SwTxtCursor*)this)->SeekAndChg( aSizeInf );
                 SwTxtSlot aDiffTxt( &aSizeInf, ((SwTxtPortion*)pPor), false, false );
                 SwFontSave aSave( aSizeInf, pPor->IsDropPortion() ?
diff --git a/sw/source/core/text/porglue.cxx b/sw/source/core/text/porglue.cxx
index d6d481f..8769a41 100644
--- a/sw/source/core/text/porglue.cxx
+++ b/sw/source/core/text/porglue.cxx
@@ -92,9 +92,9 @@ void SwGluePortion::Paint( const SwTxtPaintInfo &rInf ) const
     {
         OUStringBuffer aBuf;
         comphelper::string::padToLength(aBuf, GetFixWidth() / GetLen(), ' ');
-        String aTxt(aBuf.makeStringAndClear());
-        SwTxtPaintInfo aInf( rInf, aTxt );
-        aInf.DrawText( *this, aTxt.Len(), sal_True );
+        OUString aTxt(aBuf.makeStringAndClear());
+        SwTxtPaintInfo aInf( rInf, &aTxt );
+        aInf.DrawText( *this, aTxt.getLength(), sal_True );
     }
 
     if( rInf.OnWin() && rInf.GetOpt().IsBlank() && rInf.IsNoSymbol() )
@@ -110,7 +110,7 @@ void SwGluePortion::Paint( const SwTxtPaintInfo &rInf ) const
             SwPosSize aBulletSize( rInf.GetTxtSize( aBullet ) );
             Point aPos( rInf.GetPos() );
             aPos.X() += (Width()/2) - (aBulletSize.Width()/2);
-            SwTxtPaintInfo aInf( rInf, aBullet );
+            SwTxtPaintInfo aInf( rInf, &aBullet );
             aInf.SetPos( aPos );
             SwTxtPortion aBulletPor;
             aBulletPor.Width( aBulletSize.Width() );
diff --git a/sw/source/core/text/txttab.cxx b/sw/source/core/text/txttab.cxx
index 09cecb0..f4f3d95 100644
--- a/sw/source/core/text/txttab.cxx
+++ b/sw/source/core/text/txttab.cxx
@@ -395,7 +395,7 @@ sal_Bool SwTabPortion::PreFormat( SwTxtFormatInfo &rInf )
             pSave.reset( new SwFontSave( rInf, const_cast<SwFont*>(pNumberPortionFont) ) );
         }
         OUString aTmp( ' ' );
-        SwTxtSizeInfo aInf( rInf, aTmp );
+        SwTxtSizeInfo aInf( rInf, &aTmp );
         nMinimumTabWidth = aInf.GetTxtSize().Width();
     }
     PrtWidth( nMinimumTabWidth );


More information about the Libreoffice-commits mailing list