aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/ring.c
diff options
context:
space:
mode:
authorRobin Haberkorn <rhaberkorn@fmsbw.de>2025-12-28 16:23:22 +0100
committerRobin Haberkorn <rhaberkorn@fmsbw.de>2025-12-28 20:57:31 +0100
commitea0a23645f03a42252ab1ce8df45ae4076ebae75 (patch)
tree5fe606a9b07f2f7039b1839f9fac6bab2d212c13 /src/ring.c
parentd94521fb5b5a5c3a6315c425dba5f1218f0dd323 (diff)
teco_string_t is now passed by value like a scalar if the callee isn't expected to modify it
* When passing a struct that should not be modified, I usually use a const pointer. * Strings however are small 2-word objects and they are often now already passed via separate `gchar*` and gsize parameters. So it is consistent to pass teco_string_t by value as well. A teco_string_t will usually fit into registers just like a pointer. * It's now obvious which function just _uses_ and which function _modifies_ a string. There is also no chance to pass a NULL pointer to those functions.
Diffstat (limited to 'src/ring.c')
-rw-r--r--src/ring.c18
1 files changed, 9 insertions, 9 deletions
diff --git a/src/ring.c b/src/ring.c
index 926ee72..a608a43 100644
--- a/src/ring.c
+++ b/src/ring.c
@@ -534,7 +534,7 @@ teco_state_edit_file_initial(teco_machine_main_t *ctx, GError **error)
}
gboolean
-teco_state_edit_file_process(teco_machine_main_t *ctx, const teco_string_t *str,
+teco_state_edit_file_process(teco_machine_main_t *ctx, teco_string_t str,
gsize new_chars, GError **error)
{
g_assert(new_chars > 0);
@@ -550,18 +550,18 @@ teco_state_edit_file_process(teco_machine_main_t *ctx, const teco_string_t *str,
}
static teco_state_t *
-teco_state_edit_file_done(teco_machine_main_t *ctx, const teco_string_t *str, GError **error)
+teco_state_edit_file_done(teco_machine_main_t *ctx, teco_string_t str, GError **error)
{
if (ctx->flags.mode > TECO_MODE_NORMAL)
return &teco_state_start;
if (!ctx->flags.allow_filename) {
- /* process_cb() already throws error if str->len > 0 */
- g_assert(str->len == 0);
+ /* process_cb() already throws error if str.len > 0 */
+ g_assert(str.len == 0);
return &teco_state_start;
}
- g_autofree gchar *filename = teco_file_expand_path(str->data);
+ g_autofree gchar *filename = teco_file_expand_path(str.data);
if (teco_globber_is_pattern(filename)) {
g_auto(teco_globber_t) globber;
teco_globber_init(&globber, filename, G_FILE_TEST_IS_REGULAR);
@@ -644,7 +644,7 @@ TECO_DEFINE_STATE_EXPECTGLOB(teco_state_edit_file,
);
static teco_state_t *
-teco_state_save_file_done(teco_machine_main_t *ctx, const teco_string_t *str, GError **error)
+teco_state_save_file_done(teco_machine_main_t *ctx, teco_string_t str, GError **error)
{
if (ctx->flags.mode > TECO_MODE_NORMAL)
return &teco_state_start;
@@ -652,7 +652,7 @@ teco_state_save_file_done(teco_machine_main_t *ctx, const teco_string_t *str, GE
if (!teco_expressions_eval(FALSE, error))
return NULL;
- g_autofree gchar *filename = teco_file_expand_path(str->data);
+ g_autofree gchar *filename = teco_file_expand_path(str.data);
/*
* This is like implying teco_ring_get_id(teco_ring_current)
@@ -720,14 +720,14 @@ TECO_DEFINE_STATE_EXPECTFILE(teco_state_save_file,
);
static teco_state_t *
-teco_state_read_file_done(teco_machine_main_t *ctx, const teco_string_t *str, GError **error)
+teco_state_read_file_done(teco_machine_main_t *ctx, teco_string_t str, GError **error)
{
if (ctx->flags.mode > TECO_MODE_NORMAL)
return &teco_state_start;
sptr_t pos = teco_interface_ssm(SCI_GETCURRENTPOS, 0, 0);
- g_autofree gchar *filename = teco_file_expand_path(str->data);
+ g_autofree gchar *filename = teco_file_expand_path(str.data);
/* FIXME: Add wrapper to interface.h? */
if (!teco_view_load(teco_interface_current_view, filename, FALSE, error))
return NULL;