[Libreoffice-commits] core.git: basic/source
Arnaud Versini
Arnaud.Versini at libreoffice.org
Sun Apr 23 19:27:16 UTC 2017
basic/source/comp/token.cxx | 33 ++++++++++++++++++++-------------
basic/source/inc/token.hxx | 18 ------------------
2 files changed, 20 insertions(+), 31 deletions(-)
New commits:
commit 4a27349879ce40150c994ed49fdc8d0a6bd33d7c
Author: Arnaud Versini <Arnaud.Versini at libreoffice.org>
Date: Sun Apr 23 13:45:04 2017 +0200
BASIC: Make TokenLabelInfo a singleton, never modified and simplify it.
Change-Id: Ie233aebc39f5b181087a64d3cf2053ef4ecbab91
Reviewed-on: https://gerrit.libreoffice.org/36829
Tested-by: Jenkins <ci at libreoffice.org>
Reviewed-by: Noel Grandin <noel.grandin at collabora.co.uk>
diff --git a/basic/source/comp/token.cxx b/basic/source/comp/token.cxx
index b4de0f0d024a..4dc5d395340f 100644
--- a/basic/source/comp/token.cxx
+++ b/basic/source/comp/token.cxx
@@ -18,6 +18,8 @@
*/
+#include <array>
+
#include "basiccharclass.hxx"
#include "token.hxx"
@@ -182,31 +184,36 @@ static const TokenTable aTokTable_Basic [] = {
{ NIL, "" }
};
+// #i109076
+class TokenLabelInfo
+{
+ std::array<bool,VBASUPPORT+1> m_pTokenCanBeLabelTab;
+
+public:
+ TokenLabelInfo();
+
+ bool canTokenBeLabel( SbiToken eTok )
+ { return m_pTokenCanBeLabelTab[eTok]; }
+};
+
+class StaticTokenLabelInfo: public ::rtl::Static< TokenLabelInfo, StaticTokenLabelInfo >{};
// #i109076
TokenLabelInfo::TokenLabelInfo()
{
- m_pTokenCanBeLabelTab.reset( new bool[VBASUPPORT+1] );
- for( int i = 0 ; i <= VBASUPPORT ; ++i )
- {
- m_pTokenCanBeLabelTab[i] = false;
- }
+ m_pTokenCanBeLabelTab.fill(false);
+
// Token accepted as label by VBA
- SbiToken eLabelToken[] = { ACCESS, ALIAS, APPEND, BASE, BINARY, CLASSMODULE,
+ static const SbiToken eLabelToken[] = { ACCESS, ALIAS, APPEND, BASE, BINARY, CLASSMODULE,
COMPARE, COMPATIBLE, DEFERR, ERROR_, BASIC_EXPLICIT, LIB, LINE, LPRINT, NAME,
TOBJECT, OUTPUT, PROPERTY, RANDOM, READ, STEP, STOP, TEXT, VBASUPPORT, NIL };
SbiToken eTok;
- for( SbiToken* pTok = eLabelToken ; (eTok = *pTok) != NIL ; ++pTok )
+ for( const SbiToken* pTok = eLabelToken ; (eTok = *pTok) != NIL ; ++pTok )
{
m_pTokenCanBeLabelTab[eTok] = true;
}
}
-TokenLabelInfo::~TokenLabelInfo()
-{
-}
-
-
// the constructor detects the length of the token table
SbiTokenizer::SbiTokenizer( const OUString& rSrc, StarBASIC* pb )
@@ -542,7 +549,7 @@ special:
bool SbiTokenizer::MayBeLabel( bool bNeedsColon )
{
- if( eCurTok == SYMBOL || m_aTokenLabelInfo.canTokenBeLabel( eCurTok ) )
+ if( eCurTok == SYMBOL || StaticTokenLabelInfo::get().canTokenBeLabel( eCurTok ) )
{
return !bNeedsColon || DoesColonFollow();
}
diff --git a/basic/source/inc/token.hxx b/basic/source/inc/token.hxx
index 3ac72d52429f..6f850b814d89 100644
--- a/basic/source/inc/token.hxx
+++ b/basic/source/inc/token.hxx
@@ -114,25 +114,7 @@ enum SbiToken {
#undef SbiTokenSHAREDTMPUNDEF
#endif
-// #i109076
-class TokenLabelInfo
-{
- std::unique_ptr<bool[]> m_pTokenCanBeLabelTab;
-
-public:
- TokenLabelInfo();
- TokenLabelInfo( const TokenLabelInfo& rInfo )
- : m_pTokenCanBeLabelTab( nullptr )
- { (void)rInfo; }
- ~TokenLabelInfo();
-
- bool canTokenBeLabel( SbiToken eTok )
- { return m_pTokenCanBeLabelTab[eTok]; }
-};
-
class SbiTokenizer : public SbiScanner {
- TokenLabelInfo m_aTokenLabelInfo;
-
protected:
SbiToken eCurTok;
SbiToken ePush;
More information about the Libreoffice-commits
mailing list