[epiphany] prefs/search-engine-row: Use the "fast" variant of g_utf8_to_ucs4()
- From: Marge Bot <marge-bot src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [epiphany] prefs/search-engine-row: Use the "fast" variant of g_utf8_to_ucs4()
- Date: Tue, 28 Dec 2021 15:16:51 +0000 (UTC)
commit c3816ae486e6592c3efb00b0d7be1529e1f66e5e
Author: vanadiae <vanadiae35 gmail com>
Date: Sun Dec 26 15:38:07 2021 +0100
prefs/search-engine-row: Use the "fast" variant of g_utf8_to_ucs4()
We already hard error out anyway when there's an invalid UTF-8 character,
and the documentation of g_utf8_to_ucs4_fast() states that this function
is twice as fast as the non "fast" one. So better use it here then.
Also, since we know at the end that we're getting valid UTF-8, let's assert
instead of g_error() with a not very useful error message.
Part-of: <https://gitlab.gnome.org/GNOME/epiphany/-/merge_requests/1052>
src/preferences/ephy-search-engine-row.c | 14 +++++++-------
1 file changed, 7 insertions(+), 7 deletions(-)
---
diff --git a/src/preferences/ephy-search-engine-row.c b/src/preferences/ephy-search-engine-row.c
index 1953454a7..0c56c43bc 100644
--- a/src/preferences/ephy-search-engine-row.c
+++ b/src/preferences/ephy-search-engine-row.c
@@ -330,21 +330,21 @@ filter_str_with_functor (const char *utf8_str,
gunichar *filtered_unicode_str = g_new0 (gunichar, strlen (utf8_str) + 1);
g_autofree gunichar *unicode_str = NULL;
char *final_utf8_str = NULL;
- g_autoptr (GError) error = NULL;
int i = 0, j = 0;
- unicode_str = g_utf8_to_ucs4 (utf8_str, -1, NULL, NULL, &error);
- if (!unicode_str)
- g_error ("%s", error->message);
+ unicode_str = g_utf8_to_ucs4_fast (utf8_str, -1, NULL);
for (; unicode_str[i] != 0; ++i) {
/* If this characters matches, we add it to the final string. */
if (filter_func (unicode_str[i]))
filtered_unicode_str[j++] = unicode_str[i];
}
- final_utf8_str = g_ucs4_to_utf8 (filtered_unicode_str, -1, NULL, NULL, &error);
- if (!final_utf8_str)
- g_error ("%s", error->message);
+ final_utf8_str = g_ucs4_to_utf8 (filtered_unicode_str, -1, NULL, NULL, NULL);
+ /* We already assume it's UTF-8 when using g_utf8_to_ucs4_fast() above, and
+ * our processing can't create invalid UTF-8 characters as we are only
+ * copying existing and already valid UTF-8 characters. So it's safe to assert.
+ */
+ g_assert (final_utf8_str);
/* Would be better to use g_autofree but scan-build complains as it doesn't properly handle the cleanup
attribute. */
g_free (filtered_unicode_str);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]