diff options
author | Robin Haberkorn <robin.haberkorn@googlemail.com> | 2016-01-28 03:40:32 +0100 |
---|---|---|
committer | Robin Haberkorn <robin.haberkorn@googlemail.com> | 2016-01-28 03:40:32 +0100 |
commit | 23115c8d0a2cb942061dda1999b4487715114fa6 (patch) | |
tree | 6fc4ef9129a311342dd6065fe99d1cc9c5e1f0dc /src | |
parent | 0424327ba68803e98549b29e2115db334a6077d8 (diff) | |
download | sciteco-23115c8d0a2cb942061dda1999b4487715114fa6.tar.gz |
use String::append() instead of g_strconcat()
* it has been proven to be very efficient (at least on Linux/glibc)
Diffstat (limited to 'src')
-rw-r--r-- | src/search.cpp | 21 | ||||
-rw-r--r-- | src/string-utils.h | 4 |
2 files changed, 14 insertions, 11 deletions
diff --git a/src/search.cpp b/src/search.cpp index 4f12b72..cd1ef40 100644 --- a/src/search.cpp +++ b/src/search.cpp @@ -315,7 +315,7 @@ StateSearch::pattern2regexp(const gchar *&pattern, gchar *re = NULL; do { - gchar *new_re, *temp; + gchar *temp; /* * First check whether it is a class. @@ -333,10 +333,10 @@ StateSearch::pattern2regexp(const gchar *&pattern, if (temp) { g_assert(state == STATE_START); - new_re = g_strconcat(re ? : "", "[", temp, "]", NIL); + String::append(re, "["); + String::append(re, temp); + String::append(re, "]"); g_free(temp); - g_free(re); - re = new_re; /* class2regexp() already consumed all the bytes */ continue; @@ -369,10 +369,10 @@ StateSearch::pattern2regexp(const gchar *&pattern, goto incomplete; g_assert(state == STATE_START); - new_re = g_strconcat(re ? : "", "[^", temp, "]", NIL); + String::append(re, "[^"); + String::append(re, temp); + String::append(re, "]"); g_free(temp); - g_free(re); - re = new_re; /* class2regexp() already consumed all the bytes */ continue; @@ -406,12 +406,11 @@ StateSearch::pattern2regexp(const gchar *&pattern, if (!temp) /* a complete expression is strictly required */ goto incomplete; - /* FIXME: this might return something for an imcomplete pattern */ - new_re = g_strconcat(re ? : "", "(", temp, ")+", NIL); + String::append(re, "("); + String::append(re, temp); + String::append(re, ")+"); g_free(temp); - g_free(re); - re = new_re; state = STATE_START; /* pattern2regexp() already consumed all the bytes */ diff --git a/src/string-utils.h b/src/string-utils.h index 64112df..4eee958 100644 --- a/src/string-utils.h +++ b/src/string-utils.h @@ -44,6 +44,8 @@ chrdup(gchar chr) * Append null-terminated str2 to non-null-terminated * str1 of length str1_size. * The result is not null-terminated. + * This is a very efficient implementation and well + * suited for appending lots of small strings often. */ static inline void append(gchar *&str1, gsize str1_size, const gchar *str2) @@ -56,6 +58,8 @@ append(gchar *&str1, gsize str1_size, const gchar *str2) /** * Append str2 to str1 (both null-terminated). + * This is a very efficient implementation and well + * suited for appending lots of small strings often. */ static inline void append(gchar *&str1, const gchar *str2) |