From 3c46dad798a95b8095fac0d2ca08d9ef805c99df Mon Sep 17 00:00:00 2001 From: Markus Gans Date: Tue, 13 Oct 2020 12:55:28 +0200 Subject: [PATCH] FString optimization --- examples/termcap.cpp | 4 +- examples/ui.cpp | 2 +- src/fapplication.cpp | 11 ++--- src/fbuttongroup.cpp | 9 +--- src/ffiledialog.cpp | 2 +- src/fstring.cpp | 70 ------------------------------- src/include/final/fstring.h | 16 +++---- src/include/final/fstringstream.h | 2 +- 8 files changed, 17 insertions(+), 99 deletions(-) diff --git a/examples/termcap.cpp b/examples/termcap.cpp index f93935f7..16554f20 100644 --- a/examples/termcap.cpp +++ b/examples/termcap.cpp @@ -230,10 +230,10 @@ void debug (const finalcut::FApplication& TermApp) << debug_data.getTermType_SecDA() << "\r\n"; if ( ! ab_s.isEmpty() ) - tcapString ("| The answerback String", ab_s); + tcapString ("| The answerback String", ab_s.c_str()); if ( ! sec_da.isEmpty() ) - tcapString ("| The SecDA String", sec_da); + tcapString ("| The SecDA String", sec_da.c_str()); std::cout << "`------------------- debug -------------------\r\n"; } diff --git a/examples/ui.cpp b/examples/ui.cpp index 6e429bac..66a324f1 100644 --- a/examples/ui.cpp +++ b/examples/ui.cpp @@ -1021,7 +1021,7 @@ void MyDialog::cb_view (const finalcut::FMenuItem* item) view->setResizeable(); std::string line{""}; std::ifstream infile; - infile.open(file); + infile.open(file.c_str()); while ( ! infile.eof() && infile.good() ) { diff --git a/src/fapplication.cpp b/src/fapplication.cpp index e2c80028..4de4859f 100644 --- a/src/fapplication.cpp +++ b/src/fapplication.cpp @@ -355,7 +355,7 @@ void FApplication::setDarkTheme() void FApplication::setLogFile (const FString& filename) { auto& log_stream = getStartOptions().logfile_stream; - log_stream.open(filename, std::ofstream::out); + log_stream.open(filename.c_str(), std::ofstream::out); if ( log_stream.is_open() ) { @@ -834,10 +834,8 @@ bool FApplication::processDialogSwitchAccelerator() const //---------------------------------------------------------------------- bool FApplication::processAccelerator (const FWidget* const& widget) const { - bool accpt{false}; - if ( ! widget || widget->getAcceleratorList().empty() ) - return accpt; + return false; for (auto&& item : widget->getAcceleratorList()) { @@ -854,15 +852,14 @@ bool FApplication::processAccelerator (const FWidget* const& widget) const FAccelEvent a_ev (fc::Accelerator_Event, getFocusWidget()); sendEvent (item.object, &a_ev); - accpt = a_ev.isAccepted(); - break; + return a_ev.isAccepted(); } if ( quit_now || app_exit_loop ) break; } - return accpt; + return false; } //---------------------------------------------------------------------- diff --git a/src/fbuttongroup.cpp b/src/fbuttongroup.cpp index 0d9c3362..71571b1d 100644 --- a/src/fbuttongroup.cpp +++ b/src/fbuttongroup.cpp @@ -476,20 +476,15 @@ bool FButtonGroup::directFocusRadioButton() const if ( ! hasCheckedButton() || buttonlist.empty() ) return false; - bool found_checked{false}; - for (auto&& item : buttonlist) { auto toggle_button = static_cast(item); if ( toggle_button->isChecked() ) - { - found_checked = directFocusCheckedRadioButton(toggle_button); - break; - } + return directFocusCheckedRadioButton (toggle_button); } - return found_checked; + return false; } //---------------------------------------------------------------------- diff --git a/src/ffiledialog.cpp b/src/ffiledialog.cpp index 5b456fae..7e74f497 100644 --- a/src/ffiledialog.cpp +++ b/src/ffiledialog.cpp @@ -790,7 +790,7 @@ void FFileDialog::cb_processActivate() return ! entry.name.empty() && input && ! input.isNull() - && std::strcmp(entry.name.c_str(), input) == 0 + && std::strcmp(entry.name.c_str(), input.c_str()) == 0 && entry.directory; } ); diff --git a/src/fstring.cpp b/src/fstring.cpp index a28918eb..4dc74658 100644 --- a/src/fstring.cpp +++ b/src/fstring.cpp @@ -1534,76 +1534,6 @@ FString operator + (const FString& s1, const FString& s2) return tmp; } -//---------------------------------------------------------------------- -FString operator + (const FString& s, const wchar_t c) -{ - FString tmp1{s}; - wchar_t tmp2[2]; - tmp2[0] = c; - tmp2[1] = L'\0'; - tmp1._insert (tmp1.length, 1, tmp2); - return tmp1; -} - -//---------------------------------------------------------------------- -FString operator + (const std::wstring& s1, const FString& s2) -{ - FString tmp{s1}; - tmp._insert (tmp.length, s2.length, s2.wc_str()); - return tmp; -} - -//---------------------------------------------------------------------- -FString operator + (const wchar_t s1[], const FString& s2) -{ - FString tmp{s1}; - tmp._insert (tmp.length, s2.length, s2.wc_str()); - return tmp; -} - -//---------------------------------------------------------------------- -FString operator + (const std::string& s1, const FString& s2) -{ - FString tmp{s1}; - tmp._insert (tmp.length, s2.length, s2.wc_str()); - return tmp; -} - -//---------------------------------------------------------------------- -FString operator + (const char s1[], const FString& s2) -{ - FString tmp{s1}; - tmp._insert (tmp.length, s2.length, s2.wc_str()); - return tmp; -} - -//---------------------------------------------------------------------- -FString operator + (const wchar_t c, const FString& s) -{ - FString tmp{c}; - tmp._insert (1, s.length, s.wc_str()); - return tmp; -} - -//---------------------------------------------------------------------- -FString operator + (const char c, const FString& s) -{ - FString tmp{c}; - tmp._insert (1, s.length, s.wc_str()); - return tmp; -} - -//---------------------------------------------------------------------- -FString operator + (const FString& s, const char c) -{ - FString tmp1{s}; - wchar_t tmp2[2]; - tmp2[0] = wchar_t(c & 0xff); - tmp2[1] = L'\0'; - tmp1._insert (tmp1.length, 1, tmp2); - return tmp1; -} - //---------------------------------------------------------------------- std::ostream& operator << (std::ostream& outstr, const FString& s) { diff --git a/src/include/final/fstring.h b/src/include/final/fstring.h index 8102d4cd..f5d02195 100644 --- a/src/include/final/fstring.h +++ b/src/include/final/fstring.h @@ -113,7 +113,10 @@ class FString FString& operator << (const char); template ::value + && ! std::is_same::value + && ! std::is_pointer::value || std::is_floating_point::value + && ! std::is_pointer::value , int>::type = 0 > FString& operator << (const NumT); @@ -157,8 +160,6 @@ class FString template bool operator > (const CharT&) const; - operator const char* () const { return c_str(); } - // Accessor virtual FString getClassName() const; @@ -263,14 +264,6 @@ class FString // Friend Non-member operator functions friend FString operator + (const FString&, const FString&); - friend FString operator + (const FString&, const wchar_t); - friend FString operator + (const std::wstring&, const FString&); - friend FString operator + (const wchar_t[], const FString&); - friend FString operator + (const std::string&, const FString&); - friend FString operator + (const char[], const FString&); - friend FString operator + (const wchar_t, const FString&); - friend FString operator + (const char, const FString&); - friend FString operator + (const FString&, const char); friend std::ostream& operator << (std::ostream&, const FString&); friend std::istream& operator >> (std::istream&, FString& s); @@ -283,7 +276,10 @@ class FString //---------------------------------------------------------------------- template ::value + && ! std::is_same::value + && ! std::is_pointer::value || std::is_floating_point::value + && ! std::is_pointer::value , int>::type > inline FString& FString::operator << (const NumT val) { diff --git a/src/include/final/fstringstream.h b/src/include/final/fstringstream.h index ce10acfb..bd4e9425 100644 --- a/src/include/final/fstringstream.h +++ b/src/include/final/fstringstream.h @@ -106,7 +106,7 @@ inline std::wstringbuf* FStringStream::rdbuf() const //---------------------------------------------------------------------- inline FString FStringStream::str() const -{ return buffer.str(); } +{ return FString{buffer.str()}; } // FStringStream non-member function