aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/terminal/terminal.cc
diff options
context:
space:
mode:
authorGravatar john hood <cgull@glup.org>2014-09-28 02:48:32 -0400
committerGravatar John Hood <cgull@glup.org>2015-12-06 17:42:34 -0500
commite4a99256cb9362b71d9ae7bfcdad4c9ad86fa4ec (patch)
tree3abb6abd3e47087f84fb30a186023fbc4e5bd7eb /src/terminal/terminal.cc
parentf5d814a9c45a380d323c48730fa5ec377cce750c (diff)
Avoid wcwidth(), wcrtomb() and mbrtowc() on ASCII/ISO8859-1 characters.
ASCII <-> UTF has trivial mappings. Avoid wcrtomb() and mbrtowc(). ISO-8859-1 is all narrow characters, and cheap to test for. It might be possible to cheaply test other popular UTF blocks and/or planes as well. These two changes get 2-3x faster input processing on Linux and FreeBSD. Performance improvement in actual usage is more modest but still significant.
Diffstat (limited to 'src/terminal/terminal.cc')
-rw-r--r--src/terminal/terminal.cc12
1 files changed, 9 insertions, 3 deletions
diff --git a/src/terminal/terminal.cc b/src/terminal/terminal.cc
index 58f71be..e753cd6 100644
--- a/src/terminal/terminal.cc
+++ b/src/terminal/terminal.cc
@@ -61,7 +61,13 @@ void Emulator::print( const Parser::Print *act )
{
assert( act->char_present );
- int chwidth = act->ch == L'\0' ? -1 : wcwidth( act->ch );
+ const wchar_t ch = act->ch;
+
+ /*
+ * Check for printing ISO 8859-1 first, it's a cheap way to detect
+ * some common narrow characters.
+ */
+ const int chwidth = ch == L'\0' ? -1 : ( Cell::isprint_iso8859_1( ch ) ? 1 : wcwidth( ch ));
Cell *this_cell = fb.get_mutable_cell();
@@ -100,7 +106,7 @@ void Emulator::print( const Parser::Print *act )
}
fb.reset_cell( this_cell );
- this_cell->append( act->ch );
+ this_cell->append( ch );
this_cell->width = chwidth;
fb.apply_renditions_to_cell( this_cell );
@@ -134,7 +140,7 @@ void Emulator::print( const Parser::Print *act )
}
if ( combining_cell->contents.size() < 32 ) {
/* seems like a reasonable limit on combining characters */
- combining_cell->append( act->ch );
+ combining_cell->append( ch );
}
act->handled = true;
}