aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/qreg-commands.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/qreg-commands.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/qreg-commands.c')
-rw-r--r--src/qreg-commands.c20
1 files changed, 10 insertions, 10 deletions
diff --git a/src/qreg-commands.c b/src/qreg-commands.c
index 5efb140..304ff49 100644
--- a/src/qreg-commands.c
+++ b/src/qreg-commands.c
@@ -150,7 +150,7 @@ TECO_DEFINE_STATE_EXPECTQREG(teco_state_eqcommand,
);
static teco_state_t *
-teco_state_loadqreg_done(teco_machine_main_t *ctx, const teco_string_t *str, GError **error)
+teco_state_loadqreg_done(teco_machine_main_t *ctx, teco_string_t str, GError **error)
{
teco_qreg_t *qreg;
teco_qreg_table_t *table;
@@ -161,9 +161,9 @@ teco_state_loadqreg_done(teco_machine_main_t *ctx, const teco_string_t *str, GEr
if (ctx->flags.mode > TECO_MODE_NORMAL)
return &teco_state_start;
- if (str->len > 0) {
+ if (str.len > 0) {
/* Load file into Q-Register */
- g_autofree gchar *filename = teco_file_expand_path(str->data);
+ g_autofree gchar *filename = teco_file_expand_path(str.data);
if (!qreg->vtable->load(qreg, filename, error))
return NULL;
} else {
@@ -210,7 +210,7 @@ TECO_DEFINE_STATE_EXPECTQREG(teco_state_epctcommand,
);
static teco_state_t *
-teco_state_saveqreg_done(teco_machine_main_t *ctx, const teco_string_t *str, GError **error)
+teco_state_saveqreg_done(teco_machine_main_t *ctx, teco_string_t str, GError **error)
{
teco_qreg_t *qreg;
@@ -220,7 +220,7 @@ teco_state_saveqreg_done(teco_machine_main_t *ctx, const teco_string_t *str, GEr
if (ctx->flags.mode > TECO_MODE_NORMAL)
return &teco_state_start;
- g_autofree gchar *filename = teco_file_expand_path(str->data);
+ g_autofree gchar *filename = teco_file_expand_path(str.data);
return qreg->vtable->save(qreg, filename, error) ? &teco_state_start : NULL;
}
@@ -377,7 +377,7 @@ TECO_DEFINE_STATE_EXPECTQREG(teco_state_ctlucommand,
static teco_state_t *
teco_state_setqregstring_nobuilding_done(teco_machine_main_t *ctx,
- const teco_string_t *str, GError **error)
+ teco_string_t str, GError **error)
{
teco_qreg_t *qreg;
@@ -446,12 +446,12 @@ teco_state_setqregstring_nobuilding_done(teco_machine_main_t *ctx,
if (args > 0 || colon_modified) {
/* append to register */
- if (!qreg->vtable->append_string(qreg, str->data, str->len, error))
+ if (!qreg->vtable->append_string(qreg, str.data, str.len, error))
return NULL;
} else {
/* set register */
if (!qreg->vtable->undo_set_string(qreg, error) ||
- !qreg->vtable->set_string(qreg, str->data, str->len,
+ !qreg->vtable->set_string(qreg, str.data, str.len,
teco_default_codepage(), error))
return NULL;
}
@@ -742,12 +742,12 @@ TECO_DEFINE_STATE_EXPECTQREG(teco_state_macro,
);
static teco_state_t *
-teco_state_indirect_done(teco_machine_main_t *ctx, const teco_string_t *str, GError **error)
+teco_state_indirect_done(teco_machine_main_t *ctx, teco_string_t str, GError **error)
{
if (ctx->flags.mode > TECO_MODE_NORMAL)
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_machine_main_eval_colon(ctx) > 0) {
/* don't create new local Q-Registers if colon modifier is given */