Branch: refs/heads/master Author: Colomban Wendling ban@herbesfolles.org Committer: Colomban Wendling ban@herbesfolles.org Date: Wed, 25 Oct 2023 19:36:53 UTC Commit: 158b89854627752d266094b316b9ed08360a1858 https://github.com/geany/geany/commit/158b89854627752d266094b316b9ed08360a18...
Log Message: ----------- Replace utils_make_human_readable_str() with g_format_size()
This allows removing a needlessly complex and tricky function (I dare you understanding what it actually does the first time around) in which we even introduced subtle (but luckily invisible for now) bugs over time as it was probably not understood properly, and more sensitive to breakage than it ought to be.
It also actually improves results, as we unit for bytes, and proper translation for the units.
Note that this switches to SI units, which is probably actually better.
Modified Paths: -------------- src/dialogs.c src/utils.c src/utils.h
Modified: src/dialogs.c 2 lines changed, 1 insertions(+), 1 deletions(-) =================================================================== @@ -1195,7 +1195,7 @@ void dialogs_show_file_properties(GeanyDocument *doc) gtk_label_set_text(GTK_LABEL(label), doc->file_type->title);
label = ui_lookup_widget(dialog, "file_size_label"); - file_size = utils_make_human_readable_str(filesize, 1, 0); + file_size = g_format_size(filesize); gtk_label_set_text(GTK_LABEL(label), file_size); g_free(file_size);
Modified: src/utils.c 49 lines changed, 0 insertions(+), 49 deletions(-) =================================================================== @@ -948,55 +948,6 @@ void utils_beep(void) }
-/* taken from busybox, thanks */ -gchar *utils_make_human_readable_str(guint64 size, gulong block_size, - gulong display_unit) -{ - /* The code will adjust for additional (appended) units. */ - static const gchar zero_and_units[] = { '0', 0, 'K', 'M', 'G', 'T' }; - static const gchar fmt[] = "%Lu %c%c"; - static const gchar fmt_tenths[] = "%Lu.%d %c%c"; - - guint64 val; - gint frac; - const gchar *u; - const gchar *f; - - u = zero_and_units; - f = fmt; - frac = 0; - - val = size * block_size; - if (val == 0) - return g_strdup(u); - - if (display_unit) - { - val += display_unit/2; /* Deal with rounding. */ - val /= display_unit; /* Don't combine with the line above!!! */ - } - else - { - ++u; - while ((val >= 1024) && (u < zero_and_units + sizeof(zero_and_units) - 1)) - { - f = fmt_tenths; - ++u; - frac = ((((gint)(val % 1024)) * 10) + (1024 / 2)) / 1024; - val /= 1024; - } - if (frac >= 10) - { /* We need to round up here. */ - ++val; - frac = 0; - } - } - - /* If f==fmt then 'frac' and 'u' are ignored. */ - return g_strdup_printf(f, val, frac, *u, 'b'); -} - - /* converts a color representation using gdk_color_parse(), with additional * support of the "0x" prefix as a synonym for "#" */ gboolean utils_parse_color(const gchar *spec, GdkColor *color)
Modified: src/utils.h 3 lines changed, 0 insertions(+), 3 deletions(-) =================================================================== @@ -281,9 +281,6 @@ gchar *utils_get_current_file_dir_utf8(void);
void utils_beep(void);
-gchar *utils_make_human_readable_str(guint64 size, gulong block_size, - gulong display_unit); - gboolean utils_parse_color(const gchar *spec, GdkColor *color);
gint utils_color_to_bgr(const GdkColor *color);
-------------- This E-Mail was brought to you by github_commit_mail.py (Source: https://github.com/geany/infrastructure).