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

Noel Grandin noel.grandin at collabora.co.uk
Wed May 31 06:34:14 UTC 2017


 connectivity/source/parse/sqlflex.l |   38 +++++++++---------------------------
 1 file changed, 10 insertions(+), 28 deletions(-)

New commits:
commit 7c41a3e50433fe67eb361f79121d103929946d23
Author: Noel Grandin <noel.grandin at collabora.co.uk>
Date:   Tue May 30 11:52:34 2017 +0200

    simplify OSQLScanner::SQLyyerror
    
    ...buffer management
    
    Change-Id: I649a93ed5bd9bd7d4ac8ec73fc956eb8532eac89
    Reviewed-on: https://gerrit.libreoffice.org/38206
    Tested-by: Jenkins <ci at libreoffice.org>
    Reviewed-by: Noel Grandin <noel.grandin at collabora.co.uk>

diff --git a/connectivity/source/parse/sqlflex.l b/connectivity/source/parse/sqlflex.l
index e5008c120ff4..9d9f119fd640 100644
--- a/connectivity/source/parse/sqlflex.l
+++ b/connectivity/source/parse/sqlflex.l
@@ -717,15 +717,10 @@ void OSQLScanner::SQLyyerror(char const *fmt)
         m_sErrorMessage += ": ";
 
         ::rtl::OUString aError;
-        static sal_Int32 BUFFERSIZE = 256;
-        static sal_Char* Buffer = nullptr;
-        if(!Buffer)
-            Buffer = new sal_Char[BUFFERSIZE];
+        OUStringBuffer Buffer(256);
 
-        sal_Char *s = Buffer;
-        sal_Int32 nPos = 1;
         int ch = SQLyytext ? (SQLyytext[0] == 0 ? ' ' : SQLyytext[0]): ' ';
-        *s++ = ch;
+        Buffer.append((sal_Unicode)ch);
         while (!checkeof(ch = yyinput()))
         {
             if (ch == ' ')
@@ -735,31 +730,18 @@ void OSQLScanner::SQLyyerror(char const *fmt)
                     if (!checkeof(ch))
                         unput(ch);
                 }
-                *s = '\0';
-                aError = ::rtl::OUString(Buffer,nPos,RTL_TEXTENCODING_UTF8);
+                aError = Buffer.makeStringAndClear();
                 break;
             }
             else
             {
-                *s++ = ch;
-                if (++nPos == BUFFERSIZE)
-                {
-                    ::rtl::OString aBuf(Buffer);
-                    delete[] Buffer;
-                    BUFFERSIZE *=2;
-                    Buffer = new sal_Char[BUFFERSIZE];
-                    for(sal_Int32 i=0;i<aBuf.getLength();++i,++Buffer)
-                        *Buffer = aBuf.getStr()[i];
-                    s = &Buffer[nPos];
-    			}
-			}
-		}
-		m_sErrorMessage += aError;
-		delete[] Buffer;
-		Buffer = nullptr;
-	}
-	IN_SQLyyerror = false;
-	YY_FLUSH_BUFFER;
+                Buffer.append((sal_Unicode)ch);
+            }
+        }
+        m_sErrorMessage += aError;
+    }
+    IN_SQLyyerror = false;
+    YY_FLUSH_BUFFER;
 }
 
 //------------------------------------------------------------------------------


More information about the Libreoffice-commits mailing list