From: Daniel Carl Date: Sun, 29 Jun 2014 18:33:40 +0000 (+0200) Subject: Used g_slice_new instead of g_new. X-Git-Url: https://git.owens.tech/style.css/style.css/git?a=commitdiff_plain;h=b2c7ae62fbf5efbd9acb3be2529a69da5605ad09;p=vimb.git Used g_slice_new instead of g_new. --- diff --git a/src/bookmark.c b/src/bookmark.c index 69151ae..f988bd4 100644 --- a/src/bookmark.c +++ b/src/bookmark.c @@ -306,7 +306,7 @@ static Bookmark *line_to_bookmark(const char *line) return NULL; } - Bookmark *item = g_new0(Bookmark, 1); + Bookmark *item = g_slice_new0(Bookmark); parts = g_strsplit(line, "\t", 3); len = g_strv_length(parts); @@ -335,5 +335,5 @@ static void free_bookmark(Bookmark *bm) g_free(bm->uri); g_free(bm->title); g_strfreev(bm->tags); - g_free(bm); + g_slice_free(Bookmark, bm); } diff --git a/src/ex.c b/src/ex.c index 7fe8804..36fef1a 100644 --- a/src/ex.c +++ b/src/ex.c @@ -455,7 +455,7 @@ static void input_activate(void) gboolean ex_run_string(const char *input) { - ExArg *arg = g_new0(ExArg, 1); + ExArg *arg = g_slice_new0(ExArg); arg->lhs = g_string_new(""); arg->rhs = g_string_new(""); @@ -696,7 +696,7 @@ static void free_cmdarg(ExArg *arg) if (arg->rhs) { g_string_free(arg->rhs, true); } - g_free(arg); + g_slice_free(ExArg, arg); } static gboolean ex_bookmark(const ExArg *arg) @@ -988,7 +988,7 @@ static gboolean complete(short direction) /* skipt the first : */ in++; - ExArg *arg = g_new0(ExArg, 1); + ExArg *arg = g_slice_new0(ExArg); skip_whitespace(&in); parse_count(&in, arg); diff --git a/src/history.c b/src/history.c index 147fc46..4e3d186 100644 --- a/src/history.c +++ b/src/history.c @@ -253,7 +253,7 @@ static History *line_to_history(const char *line) return NULL; } - History *item = g_new0(History, 1); + History *item = g_slice_new0(History); parts = g_strsplit(line, "\t", 2); len = g_strv_length(parts); @@ -301,5 +301,5 @@ static void free_history(History *item) { g_free(item->first); g_free(item->second); - g_free(item); + g_slice_free(History, item); } diff --git a/src/hsts.c b/src/hsts.c index 1e09c9e..c579cfd 100644 --- a/src/hsts.c +++ b/src/hsts.c @@ -259,7 +259,7 @@ static void parse_hsts_header(HSTSProvider *provider, if (max_age == 0) { remove_host_entry(provider, host); } else { - entry = g_new(HSTSEntry, 1); + entry = g_slice_new(HSTSEntry); entry->expires_at = soup_date_new_from_now(max_age); entry->include_sub_domains = include_sub_domains; @@ -272,7 +272,7 @@ static void parse_hsts_header(HSTSProvider *provider, static void free_entry(HSTSEntry *entry) { soup_date_free(entry->expires_at); - g_free(entry); + g_slice_free(HSTSEntry, entry); } /** @@ -397,7 +397,7 @@ static void load_entries(HSTSProvider *provider, const char *file) include_sub_domains = (*parts[2] == 'y') ? true : false; /* built the new entry to add */ - entry = g_new(HSTSEntry, 1); + entry = g_slice_new(HSTSEntry); entry->expires_at = soup_date_new_from_string(parts[1]); entry->include_sub_domains = include_sub_domains; diff --git a/src/input.c b/src/input.c index d2fe8a5..9827da8 100644 --- a/src/input.c +++ b/src/input.c @@ -129,7 +129,7 @@ VbResult input_open_editor(void) /* disable the active element */ dom_editable_element_set_disable(active, true); - EditorData *data = g_new0(EditorData, 1); + EditorData *data = g_slice_new0(EditorData); data->file = file_path; data->element = active; @@ -152,6 +152,6 @@ static void resume_editor(GPid pid, int status, EditorData *data) g_unlink(data->file); g_free(data->file); - g_free(data); + g_slice_free(EditorData, data); g_spawn_close_pid(pid); } diff --git a/src/map.c b/src/map.c index 7190686..93067bb 100644 --- a/src/map.c +++ b/src/map.c @@ -341,7 +341,7 @@ void map_insert(const char *in, const char *mapped, char mode, gboolean remap) /* if lhs was already mapped, remove this first */ map_delete_by_lhs(lhs, inlen, mode); - Map *new = g_new(Map, 1); + Map *new = g_slice_new(Map); new->in = lhs; new->inlen = inlen; new->mapped = rhs; @@ -590,5 +590,5 @@ static void free_map(Map *map) { g_free(map->in); g_free(map->mapped); - g_free(map); + g_slice_free(Map, map); } diff --git a/src/mode.c b/src/mode.c index 7af00b6..5cfaf03 100644 --- a/src/mode.c +++ b/src/mode.c @@ -27,9 +27,12 @@ static GHashTable *modes = NULL; extern VbCore vb; +static void free_mode(Mode *mode); + + void mode_init(void) { - modes = g_hash_table_new_full(g_direct_hash, g_direct_equal, NULL, g_free); + modes = g_hash_table_new_full(g_direct_hash, g_direct_equal, NULL, (GDestroyNotify)free_mode); } void mode_cleanup(void) @@ -46,7 +49,7 @@ void mode_cleanup(void) void mode_add(char id, ModeTransitionFunc enter, ModeTransitionFunc leave, ModeKeyFunc keypress, ModeInputChangedFunc input_changed) { - Mode *new = g_new(Mode, 1); + Mode *new = g_slice_new(Mode); new->id = id; new->enter = enter; new->leave = leave; @@ -182,3 +185,8 @@ void mode_input_changed(GtkTextBuffer* buffer, gpointer data) g_free(text); } } + +static void free_mode(Mode *mode) +{ + g_slice_free(Mode, mode); +}