Small optimizations

This commit is contained in:
Markus Gans 2018-10-02 01:03:44 +02:00
parent 8407a9d2b6
commit f19b4811ae
6 changed files with 92 additions and 69 deletions

View File

@ -2675,40 +2675,45 @@ inline void FString::_assign (const wchar_t s[])
length = new_length; length = new_length;
} }
//----------------------------------------------------------------------
inline void FString::_insert (uInt len, const wchar_t s[])
{
if ( len == 0 ) // String s is a null or a empty string
return;
if ( string )
delete[](string);
length = len;
bufsize = FWDBUFFER + length + 1;
try
{
string = new wchar_t[bufsize]();
}
catch (const std::bad_alloc& ex)
{
std::cerr << bad_alloc_str << " " << ex.what() << std::endl;
return;
}
std::wcsncpy (string, s, bufsize);
string[bufsize - 1] = L'\0';
}
//---------------------------------------------------------------------- //----------------------------------------------------------------------
inline void FString::_insert (uInt pos, uInt len, const wchar_t s[]) inline void FString::_insert (uInt pos, uInt len, const wchar_t s[])
{ {
if ( len == 0 ) // String s is a null or a empty string if ( len == 0 ) // String s is a null or a empty string
return; return;
if ( ! string ) if ( ! string ) // string is null
{ {
// string is null _insert (len, s);
length = len;
bufsize = FWDBUFFER + length + 1;
try
{
string = new wchar_t[bufsize]();
}
catch (const std::bad_alloc& ex)
{
std::cerr << bad_alloc_str << " " << ex.what() << std::endl;
return;
}
std::wcsncpy (string, s, bufsize);
string[bufsize - 1] = L'\0';
return;
} }
else else
{ {
uInt x; uInt x;
uInt insert_len = uInt(std::wcslen(s));
if ( len > insert_len )
len = insert_len;
if ( (length + len + 1) <= bufsize ) if ( (length + len + 1) <= bufsize )
{ {

View File

@ -1259,6 +1259,46 @@ void FTerm::init_termcap_strings (char*& buffer)
tcap[i].string = tgetstr(tcap[i].tname, &buffer); tcap[i].string = tgetstr(tcap[i].tname, &buffer);
} }
//----------------------------------------------------------------------
void FTerm::init_termcap_keys_vt100 (char*& buffer)
{
// Some terminals (e.g. PuTTY) send vt100 key codes for
// the arrow and function keys.
char* key_up_string = tgetstr(C_STR("ku"), &buffer);
if ( (key_up_string && (std::strcmp(key_up_string, CSI "A") == 0))
|| ( TCAP(fc::t_cursor_up)
&& (std::strcmp(TCAP(fc::t_cursor_up), CSI "A") == 0) ) )
{
for (int i = 0; fc::Fkey[i].tname[0] != 0; i++)
{
if ( std::strncmp(fc::Fkey[i].tname, "kux", 3) == 0 )
fc::Fkey[i].string = C_STR(CSI "A"); // Key up
if ( std::strncmp(fc::Fkey[i].tname, "kdx", 3) == 0 )
fc::Fkey[i].string = C_STR(CSI "B"); // Key down
if ( std::strncmp(fc::Fkey[i].tname, "krx", 3) == 0 )
fc::Fkey[i].string = C_STR(CSI "C"); // Key right
if ( std::strncmp(fc::Fkey[i].tname, "klx", 3) == 0 )
fc::Fkey[i].string = C_STR(CSI "D"); // Key left
if ( std::strncmp(fc::Fkey[i].tname, "k1X", 3) == 0 )
fc::Fkey[i].string = C_STR(ESC "OP"); // PF1
if ( std::strncmp(fc::Fkey[i].tname, "k2X", 3) == 0 )
fc::Fkey[i].string = C_STR(ESC "OQ"); // PF2
if ( std::strncmp(fc::Fkey[i].tname, "k3X", 3) == 0 )
fc::Fkey[i].string = C_STR(ESC "OR"); // PF3
if ( std::strncmp(fc::Fkey[i].tname, "k4X", 3) == 0 )
fc::Fkey[i].string = C_STR(ESC "OS"); // PF4
}
}
}
//---------------------------------------------------------------------- //----------------------------------------------------------------------
void FTerm::init_termcap_keys (char*& buffer) void FTerm::init_termcap_keys (char*& buffer)
{ {
@ -1308,42 +1348,8 @@ void FTerm::init_termcap_keys (char*& buffer)
fc::Fkey[i].string = C_STR(ESC "Ok"); // Keypad plus sign fc::Fkey[i].string = C_STR(ESC "Ok"); // Keypad plus sign
} }
// Some terminals (e.g. PuTTY) send the wrong code for the arrow keys // VT100 key codes for the arrow and function keys
// http://www.unix.com/shell-programming-scripting/.. init_termcap_keys_vt100(buffer);
// ..110380-using-arrow-keys-shell-scripts.html
char* key_up_string = tgetstr(C_STR("ku"), &buffer);
if ( (key_up_string && (std::strcmp(key_up_string, CSI "A") == 0))
|| ( TCAP(fc::t_cursor_up)
&& (std::strcmp(TCAP(fc::t_cursor_up), CSI "A") == 0) ) )
{
for (int i = 0; fc::Fkey[i].tname[0] != 0; i++)
{
if ( std::strncmp(fc::Fkey[i].tname, "kux", 3) == 0 )
fc::Fkey[i].string = C_STR(CSI "A"); // Key up
if ( std::strncmp(fc::Fkey[i].tname, "kdx", 3) == 0 )
fc::Fkey[i].string = C_STR(CSI "B"); // Key down
if ( std::strncmp(fc::Fkey[i].tname, "krx", 3) == 0 )
fc::Fkey[i].string = C_STR(CSI "C"); // Key right
if ( std::strncmp(fc::Fkey[i].tname, "klx", 3) == 0 )
fc::Fkey[i].string = C_STR(CSI "D"); // Key left
if ( std::strncmp(fc::Fkey[i].tname, "k1X", 3) == 0 )
fc::Fkey[i].string = C_STR(ESC "OP"); // PF1
if ( std::strncmp(fc::Fkey[i].tname, "k2X", 3) == 0 )
fc::Fkey[i].string = C_STR(ESC "OQ"); // PF2
if ( std::strncmp(fc::Fkey[i].tname, "k3X", 3) == 0 )
fc::Fkey[i].string = C_STR(ESC "OR"); // PF3
if ( std::strncmp(fc::Fkey[i].tname, "k4X", 3) == 0 )
fc::Fkey[i].string = C_STR(ESC "OS"); // PF4
}
}
} }
//---------------------------------------------------------------------- //----------------------------------------------------------------------
@ -1982,14 +1988,8 @@ void FTerm::init (bool disable_alt_screen)
// Save the used xterm font and window title // Save the used xterm font and window title
init_captureFontAndTitle(); init_captureFontAndTitle();
if ( isKdeTerminal() ) // KDE terminal cursor and cygwin + teraterm charmap correction
setKDECursor(fc::UnderlineCursor); initTermspecifics();
if ( isCygwinTerminal() )
init_cygwin_charmap();
if ( isTeraTerm() )
init_teraterm_charmap();
// Redefine the color palette // Redefine the color palette
if ( init_values.color_change ) if ( init_values.color_change )
@ -2055,6 +2055,19 @@ void FTerm::initOSspecifics()
#endif #endif
} }
//----------------------------------------------------------------------
void FTerm::initTermspecifics()
{
if ( isKdeTerminal() )
setKDECursor(fc::UnderlineCursor);
if ( isCygwinTerminal() )
init_cygwin_charmap();
if ( isTeraTerm() )
init_teraterm_charmap();
}
//---------------------------------------------------------------------- //----------------------------------------------------------------------
void FTerm::finish() void FTerm::finish()
{ {

View File

@ -382,6 +382,7 @@ class FString
// Methods // Methods
void initLength (uInt); void initLength (uInt);
void _assign (const wchar_t[]); void _assign (const wchar_t[]);
void _insert (uInt, const wchar_t[]);
void _insert (uInt, uInt, const wchar_t[]); void _insert (uInt, uInt, const wchar_t[]);
void _remove (uInt, uInt); void _remove (uInt, uInt);
char* wc_to_c_str (const wchar_t[]) const; char* wc_to_c_str (const wchar_t[]) const;

View File

@ -387,6 +387,7 @@ class FTerm
static void init_termcap_booleans(); static void init_termcap_booleans();
static void init_termcap_numerics(); static void init_termcap_numerics();
static void init_termcap_strings (char*&); static void init_termcap_strings (char*&);
static void init_termcap_keys_vt100 (char*&);
static void init_termcap_keys (char*&); static void init_termcap_keys (char*&);
static void init_OptiMove(); static void init_OptiMove();
static void init_OptiAttr(); static void init_OptiAttr();
@ -412,6 +413,7 @@ class FTerm
void deallocationValues(); void deallocationValues();
void init (bool); void init (bool);
void initOSspecifics(); void initOSspecifics();
void initTermspecifics();
void finish(); void finish();
void finishOSspecifics1(); void finishOSspecifics1();
void finish_encoding(); void finish_encoding();

View File

@ -181,6 +181,9 @@ inline FTermData::FTermData()
, termfilename() , termfilename()
, xterm_font() , xterm_font()
, xterm_title() , xterm_title()
#if DEBUG
, framebuffer_bpp(-1)
#endif
{ {
// Initialize arrays with '\0' // Initialize arrays with '\0'
std::fill_n (termtype, sizeof(termtype), '\0'); std::fill_n (termtype, sizeof(termtype), '\0');
@ -370,7 +373,7 @@ inline void FTermData::setTermFileName (const char file_name[])
return; return;
std::strncpy (termfilename, file_name, sizeof(termfilename)); std::strncpy (termfilename, file_name, sizeof(termfilename));
termtype[sizeof(termfilename) - 1] = '\0'; termfilename[sizeof(termfilename) - 1] = '\0';
} }
//---------------------------------------------------------------------- //----------------------------------------------------------------------

View File

@ -287,7 +287,6 @@ void FTermcapQuirksTest::generalTest()
, C_STR(CSI "29m") ); , C_STR(CSI "29m") );
CPPUNIT_ASSERT_CSTRING ( printSequence(caps[finalcut::fc::t_enter_ca_mode].string).c_str() CPPUNIT_ASSERT_CSTRING ( printSequence(caps[finalcut::fc::t_enter_ca_mode].string).c_str()
, C_STR("Esc 7 Esc [ ? 4 7 h ") ); , C_STR("Esc 7 Esc [ ? 4 7 h ") );
//delete[] caps;
} }
//---------------------------------------------------------------------- //----------------------------------------------------------------------