Avoid copying of strings and making tiny allocations
This commit is contained in:
parent
622628b9c3
commit
c8b19b2eeb
6 changed files with 42 additions and 50 deletions
|
@ -216,12 +216,10 @@ settings_save_to_file (MidoriWebSettings* settings,
|
|||
}
|
||||
|
||||
g_object_get (settings, property, &string, NULL);
|
||||
if (!string)
|
||||
string = g_strdup ("");
|
||||
if (!def_string)
|
||||
def_string = "";
|
||||
if (strcmp (string, def_string))
|
||||
g_key_file_set_string (key_file, "settings", property, string);
|
||||
if (strcmp (string ? string : "", def_string))
|
||||
g_key_file_set_string (key_file, "settings", property, string ? string : "");
|
||||
g_free (string);
|
||||
}
|
||||
else if (type == G_TYPE_PARAM_INT)
|
||||
|
@ -1405,8 +1403,7 @@ midori_load_session (gpointer data)
|
|||
{
|
||||
katze_item_set_meta_integer (item, "append", 1);
|
||||
katze_item_set_meta_integer (item, "dont-write-history", 1);
|
||||
if (load_on_startup == MIDORI_STARTUP_DELAYED_PAGES
|
||||
&& katze_item_get_meta_integer (item, "delay") == -1)
|
||||
if (load_on_startup == MIDORI_STARTUP_DELAYED_PAGES)
|
||||
katze_item_set_meta_integer (item, "delay", 1);
|
||||
midori_browser_add_item (browser, item);
|
||||
}
|
||||
|
|
|
@ -796,7 +796,7 @@ katze_item_metadata_to_xbel (KatzeItem* item)
|
|||
const gchar* value;
|
||||
|
||||
if (!keys)
|
||||
return g_strdup ("");
|
||||
return NULL;
|
||||
|
||||
markup = g_string_new ("<info>\n<metadata");
|
||||
markdown = g_string_new (NULL);
|
||||
|
@ -856,7 +856,7 @@ katze_array_to_xbel (KatzeArray* array,
|
|||
">\n");
|
||||
string_append_xml_element (markup, "title", katze_item_get_name (KATZE_ITEM (array)));
|
||||
string_append_xml_element (markup, "desc", katze_item_get_text (KATZE_ITEM (array)));
|
||||
g_string_append (markup, metadata);
|
||||
g_string_append (markup, metadata ? metadata : "");
|
||||
KATZE_ARRAY_FOREACH_ITEM_L (item, array, list)
|
||||
string_append_item (markup, item);
|
||||
g_string_append (markup, "</xbel>\n");
|
||||
|
|
|
@ -3341,17 +3341,17 @@ midori_browser_get_uri_extension (const gchar* uri)
|
|||
slash = strrchr (uri, '/');
|
||||
/* Huh, URI without slashes? */
|
||||
if (!slash)
|
||||
return g_strdup ("");
|
||||
return NULL;
|
||||
|
||||
ext_end = period = strrchr (slash, '.');
|
||||
if (!period)
|
||||
return g_strdup ("");
|
||||
return NULL;
|
||||
|
||||
/* Skip the period */
|
||||
ext_end++;
|
||||
/* If *ext_end is 0 here, the URI ended with a period, so skip */
|
||||
if (!*ext_end)
|
||||
return g_strdup ("");
|
||||
return NULL;
|
||||
|
||||
/* Find the end of the extension */
|
||||
while (*ext_end && g_ascii_isalnum (*ext_end))
|
||||
|
@ -5489,7 +5489,7 @@ midori_browser_size_allocate_cb (MidoriBrowser* browser,
|
|||
{
|
||||
GtkWidget* widget = GTK_WIDGET (browser);
|
||||
|
||||
if (gtk_widget_get_realized (widget) && !browser->alloc_timeout)
|
||||
if (!browser->alloc_timeout && gtk_widget_get_realized (widget))
|
||||
{
|
||||
gpointer last_page;
|
||||
|
||||
|
|
|
@ -1951,8 +1951,8 @@ gtk_widget_key_press_event_cb (WebKitWebView* web_view,
|
|||
if (!webkit_web_view_can_cut_clipboard (web_view)
|
||||
&& !webkit_web_view_can_paste_clipboard (web_view))
|
||||
{
|
||||
gchar* text = character ? g_strdup_printf ("%c", character) : g_strdup ("");
|
||||
g_signal_emit (view, signals[SEARCH_TEXT], 0, TRUE, text);
|
||||
gchar* text = character ? g_strdup_printf ("%c", character) : NULL;
|
||||
g_signal_emit (view, signals[SEARCH_TEXT], 0, TRUE, text ? text : "");
|
||||
g_free (text);
|
||||
return TRUE;
|
||||
}
|
||||
|
@ -3720,7 +3720,7 @@ prepare_speed_dial_html (MidoriView* view,
|
|||
else
|
||||
{
|
||||
g_free (file_path);
|
||||
return g_strdup ("");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
groups = g_key_file_get_groups (key_file, NULL);
|
||||
|
@ -3774,7 +3774,7 @@ prepare_speed_dial_html (MidoriView* view,
|
|||
}
|
||||
else
|
||||
{
|
||||
encoded = g_strdup ("");
|
||||
encoded = NULL;
|
||||
if (load_missing)
|
||||
midori_view_speed_dial_get_thumb (view, groups[i], uri);
|
||||
}
|
||||
|
@ -3785,7 +3785,7 @@ prepare_speed_dial_html (MidoriView* view,
|
|||
"<a class=\"cross\" href=\"#\" onclick='clearShortcut(\"s%d\");'></a>"
|
||||
"<a href=\"%s\"><img src=\"data:image/png;base64,%s\"></a>"
|
||||
"</div><div class=\"title\" onclick='renameShortcut(\"s%d\");'>%s</div></div>\n",
|
||||
slot, slot, uri, encoded, slot, title ? title : "");
|
||||
slot, slot, uri, encoded ? encoded : "", slot, title ? title : "");
|
||||
|
||||
g_free (title);
|
||||
g_free (encoded);
|
||||
|
@ -3848,7 +3848,7 @@ midori_view_set_uri (MidoriView* view,
|
|||
speeddial_markup = prepare_speed_dial_html (view, TRUE);
|
||||
|
||||
midori_view_load_alternate_string (view,
|
||||
speeddial_markup, "about:blank", NULL);
|
||||
speeddial_markup ? speeddial_markup : "", "about:blank", NULL);
|
||||
|
||||
#ifdef G_ENABLE_DEBUG
|
||||
if (g_getenv ("MIDORI_STARTTIME") != NULL)
|
||||
|
@ -3960,7 +3960,7 @@ midori_view_set_uri (MidoriView* view,
|
|||
katze_item_set_uri (view->item, view->uri);
|
||||
g_object_notify (G_OBJECT (view), "uri");
|
||||
}
|
||||
else if (katze_item_get_meta_integer (view->item, "delay") > 0)
|
||||
else if (katze_item_get_meta_boolean (view->item, "delay"))
|
||||
{
|
||||
katze_assign (view->uri, g_strdup (uri));
|
||||
katze_item_set_meta_integer (view->item, "delay", -1);
|
||||
|
|
|
@ -1701,7 +1701,7 @@ midori_download_prepare_tooltip_text (WebKitDownload* download)
|
|||
|
||||
if (time_estimated > 0)
|
||||
{
|
||||
gchar* eta;
|
||||
gchar* eta = NULL;
|
||||
if (hours_left > 0)
|
||||
eta = g_strdup_printf ("%s, %s", hours_str, minutes_str);
|
||||
else if (minutes_left >= 10)
|
||||
|
@ -1710,12 +1710,13 @@ midori_download_prepare_tooltip_text (WebKitDownload* download)
|
|||
eta = g_strdup_printf ("%s, %s", minutes_str, seconds_str);
|
||||
else if (seconds_left > 0)
|
||||
eta = g_strdup_printf ("%s", seconds_str);
|
||||
else
|
||||
eta = g_strdup ("");
|
||||
if (eta != NULL)
|
||||
{
|
||||
/* i18n: Download tooltip (estimated time) : - 1 hour, 5 minutes remaning */
|
||||
g_string_append_printf (tooltip, _(" - %s remaining"), eta);
|
||||
g_free (eta);
|
||||
}
|
||||
}
|
||||
|
||||
g_free (hours_str);
|
||||
g_free (seconds_str);
|
||||
|
|
|
@ -216,9 +216,9 @@ midori_bookmarks_insert_item_db (sqlite3* db,
|
|||
gchar* sqlcmd;
|
||||
char* errmsg = NULL;
|
||||
KatzeItem* old_parent;
|
||||
gchar* parent;
|
||||
gchar* uri;
|
||||
gchar* desc;
|
||||
const gchar* parent;
|
||||
const gchar* uri = NULL;
|
||||
const gchar* desc = NULL;
|
||||
|
||||
/* Bookmarks must have a name, import may produce invalid items */
|
||||
g_return_if_fail (katze_item_get_name (item));
|
||||
|
@ -227,30 +227,26 @@ midori_bookmarks_insert_item_db (sqlite3* db,
|
|||
return;
|
||||
|
||||
if (KATZE_ITEM_IS_BOOKMARK (item))
|
||||
uri = g_strdup (katze_item_get_uri (item));
|
||||
else
|
||||
uri = g_strdup ("");
|
||||
uri = katze_item_get_uri (item);
|
||||
|
||||
if (katze_item_get_text (item))
|
||||
desc = g_strdup (katze_item_get_text (item));
|
||||
else
|
||||
desc = g_strdup ("");
|
||||
desc = katze_item_get_text (item);
|
||||
|
||||
/* Use folder, otherwise fallback to parent folder */
|
||||
old_parent = katze_item_get_parent (item);
|
||||
if (folder && *folder)
|
||||
parent = g_strdup (folder);
|
||||
parent = folder;
|
||||
else if (old_parent && katze_item_get_name (old_parent))
|
||||
parent = g_strdup (katze_item_get_name (old_parent));
|
||||
parent = katze_item_get_name (old_parent);
|
||||
else
|
||||
parent = g_strdup ("");
|
||||
parent = "";
|
||||
|
||||
sqlcmd = sqlite3_mprintf (
|
||||
"INSERT into bookmarks (uri, title, desc, folder, toolbar, app) values"
|
||||
" ('%q', '%q', '%q', '%q', %d, %d)",
|
||||
uri,
|
||||
uri ? uri : "",
|
||||
katze_item_get_name (item),
|
||||
desc,
|
||||
desc ? desc : "",
|
||||
parent,
|
||||
katze_item_get_meta_boolean (item, "toolbar"),
|
||||
katze_item_get_meta_boolean (item, "app"));
|
||||
|
@ -261,9 +257,6 @@ midori_bookmarks_insert_item_db (sqlite3* db,
|
|||
sqlite3_free (errmsg);
|
||||
}
|
||||
|
||||
g_free (uri);
|
||||
g_free (parent);
|
||||
g_free (desc);
|
||||
sqlite3_free (sqlcmd);
|
||||
}
|
||||
|
||||
|
@ -315,30 +308,31 @@ midori_bookmarks_row_changed_cb (GtkTreeModel* model,
|
|||
{
|
||||
KatzeItem* item;
|
||||
GtkTreeIter parent;
|
||||
gchar* parent_name;
|
||||
KatzeItem* new_parent = NULL;
|
||||
const gchar* parent_name;
|
||||
|
||||
gtk_tree_model_get (model, iter, 0, &item, -1);
|
||||
|
||||
if (gtk_tree_model_iter_parent (model, &parent, iter))
|
||||
{
|
||||
KatzeItem* new_parent;
|
||||
|
||||
gtk_tree_model_get (model, &parent, 0, &new_parent, -1);
|
||||
|
||||
/* Bookmarks must not be moved into non-folder items */
|
||||
if (!KATZE_ITEM_IS_FOLDER (new_parent))
|
||||
parent_name = g_strdup ("");
|
||||
parent_name = "";
|
||||
else
|
||||
parent_name = g_strdup (katze_item_get_name (new_parent));
|
||||
|
||||
g_object_unref (new_parent);
|
||||
parent_name = katze_item_get_name (new_parent);
|
||||
}
|
||||
else
|
||||
parent_name = g_strdup ("");
|
||||
parent_name = "";
|
||||
|
||||
katze_array_remove_item (bookmarks->array, item);
|
||||
katze_item_set_meta_string (item, "folder", parent_name);
|
||||
katze_array_add_item (bookmarks->array, item);
|
||||
|
||||
g_object_unref (item);
|
||||
if (new_parent)
|
||||
g_object_unref (new_parent);
|
||||
}
|
||||
|
||||
static void
|
||||
|
|
Loading…
Reference in a new issue