aboutsummaryrefslogtreecommitdiffhomepage
path: root/src
diff options
context:
space:
mode:
authorRobin Haberkorn <robin.haberkorn@googlemail.com>2016-02-10 16:30:16 +0100
committerRobin Haberkorn <robin.haberkorn@googlemail.com>2016-02-10 16:30:16 +0100
commit723b75534632a99228a7266d7579c9d8b3f0cb77 (patch)
treedb1cae271ddf0723090f99f5a190ad83b986222b /src
parent1da5bdeb986657c5cfd83d495d15b7f2308d3b5b (diff)
downloadsciteco-723b75534632a99228a7266d7579c9d8b3f0cb77.tar.gz
added String::toupper(): minor optimization
* This is one of the most called functions (although a cheap one), so having our own inline implementation speeds up things. Benchmarks have shown that parsing is sped up by at least 4%.
Diffstat (limited to 'src')
-rw-r--r--src/parser.cpp20
-rw-r--r--src/qregisters.cpp6
-rw-r--r--src/search.cpp4
-rw-r--r--src/string-utils.h12
4 files changed, 27 insertions, 15 deletions
diff --git a/src/parser.cpp b/src/parser.cpp
index 2ae6f73..5748c78 100644
--- a/src/parser.cpp
+++ b/src/parser.cpp
@@ -282,7 +282,7 @@ State *
State::get_next_state(gchar chr)
{
State *next = NULL;
- guint upper = g_ascii_toupper(chr);
+ guint upper = String::toupper(chr);
if (upper < G_N_ELEMENTS(transitions))
next = transitions[upper];
@@ -321,7 +321,7 @@ StringBuildingMachine::input(gchar chr, gchar *&result)
if (toctl) {
if (chr != '^')
- chr = CTL_KEY(g_ascii_toupper(chr));
+ chr = CTL_KEY(String::toupper(chr));
undo.push_var(toctl) = false;
} else if (chr == '^') {
undo.push_var(toctl) = true;
@@ -364,7 +364,7 @@ StateUpper:
return false;
StateCtlE:
- switch (g_ascii_toupper(chr)) {
+ switch (String::toupper(chr)) {
case '\\':
undo.push_obj(qregspec_machine) = new QRegSpecMachine;
set(&&StateCtlENum);
@@ -448,7 +448,7 @@ StateExpectString::custom(gchar chr)
switch (escape_char) {
case CTL_KEY_ESC:
case '{':
- undo.push_var(escape_char) = g_ascii_toupper(chr);
+ undo.push_var(escape_char) = String::toupper(chr);
return this;
}
}
@@ -462,7 +462,7 @@ StateExpectString::custom(gchar chr)
undo.push_var(nesting)--;
break;
}
- } else if (g_ascii_toupper(chr) == escape_char) {
+ } else if (String::toupper(chr) == escape_char) {
undo.push_var(nesting)--;
}
@@ -589,7 +589,7 @@ StateStart::read_integer(void)
}
for (;;) {
- c = g_ascii_toupper((gchar)interface.ssm(SCI_GETCHARAT, pos));
+ c = String::toupper((gchar)interface.ssm(SCI_GETCHARAT, pos));
if (c >= '0' && c <= '0' + MIN(expressions.radix, 10) - 1)
v = (v*expressions.radix) + (c - '0');
else if (c >= 'A' &&
@@ -724,7 +724,7 @@ StateStart::custom(gchar chr)
return this;
}
- chr = g_ascii_toupper(chr);
+ chr = String::toupper(chr);
switch (chr) {
case '/':
BEGIN_EXEC(this);
@@ -1689,7 +1689,7 @@ StateCondCommand::custom(gchar chr)
break;
}
- switch (g_ascii_toupper(chr)) {
+ switch (String::toupper(chr)) {
case '~':
BEGIN_EXEC(&States::start);
result = !expressions.args();
@@ -1774,7 +1774,7 @@ StateControl::StateControl() : State()
State *
StateControl::custom(gchar chr)
{
- switch (g_ascii_toupper(chr)) {
+ switch (String::toupper(chr)) {
/*$
* ^O -- Set radix to 8 (octal)
*/
@@ -1917,7 +1917,7 @@ StateECommand::StateECommand() : State()
State *
StateECommand::custom(gchar chr)
{
- switch (g_ascii_toupper(chr)) {
+ switch (String::toupper(chr)) {
/*$
* [bool]EF -- Remove buffer from ring
* -EF
diff --git a/src/qregisters.cpp b/src/qregisters.cpp
index 5283ce7..995edb9 100644
--- a/src/qregisters.cpp
+++ b/src/qregisters.cpp
@@ -807,7 +807,7 @@ MICROSTATE_START;
case '#': set(&&StateFirstChar); break;
case '[': set(&&StateString); break;
default:
- undo.push_str(name) = String::chrdup(g_ascii_toupper(chr));
+ undo.push_str(name) = String::chrdup(String::toupper(chr));
goto done;
}
@@ -815,12 +815,12 @@ MICROSTATE_START;
StateFirstChar:
undo.push_str(name) = (gchar *)g_malloc(3);
- name[0] = g_ascii_toupper(chr);
+ name[0] = String::toupper(chr);
set(&&StateSecondChar);
return false;
StateSecondChar:
- name[1] = g_ascii_toupper(chr);
+ name[1] = String::toupper(chr);
name[2] = '\0';
goto done;
diff --git a/src/search.cpp b/src/search.cpp
index cd1ef40..3a493ff 100644
--- a/src/search.cpp
+++ b/src/search.cpp
@@ -210,7 +210,7 @@ StateSearch::class2regexp(MatchState &state, const gchar *&pattern,
break;
case STATE_CTL_E:
- switch (g_ascii_toupper(*pattern)) {
+ switch (String::toupper(*pattern)) {
case 'A':
pattern++;
state = STATE_START;
@@ -379,7 +379,7 @@ StateSearch::pattern2regexp(const gchar *&pattern,
case STATE_CTL_E:
state = STATE_START;
- switch (g_ascii_toupper(*pattern)) {
+ switch (String::toupper(*pattern)) {
case 'M': state = STATE_MANY; break;
case 'S': String::append(re, "\\s+"); break;
/* same as <CTRL/X> */
diff --git a/src/string-utils.h b/src/string-utils.h
index 4eee958..559e590 100644
--- a/src/string-utils.h
+++ b/src/string-utils.h
@@ -27,6 +27,18 @@ namespace SciTECO {
namespace String {
/**
+ * Upper-case ASCII character.
+ *
+ * There are implementations in glib and libc,
+ * but defining it here ensures it can be inlined.
+ */
+static inline gchar
+toupper(gchar chr)
+{
+ return chr >= 'a' && chr <= 'z' ? chr & ~0x20 : chr;
+}
+
+/**
* Allocate a string containing a single character chr.
*/
static inline gchar *