aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/core-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/core-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/core-commands.c')
-rw-r--r--src/core-commands.c14
1 files changed, 7 insertions, 7 deletions
diff --git a/src/core-commands.c b/src/core-commands.c
index 86a4b85..949952e 100644
--- a/src/core-commands.c
+++ b/src/core-commands.c
@@ -1108,12 +1108,12 @@ teco_undo_change_dir_to_current(void)
}
static teco_state_t *
-teco_state_changedir_done(teco_machine_main_t *ctx, const teco_string_t *str, GError **error)
+teco_state_changedir_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 *dir = teco_file_expand_path(str->data);
+ g_autofree gchar *dir = teco_file_expand_path(str.data);
if (!*dir) {
teco_qreg_t *qreg = teco_qreg_table_find(&teco_qreg_table_globals, "$HOME", 5);
g_assert(qreg != NULL);
@@ -1124,7 +1124,7 @@ teco_state_changedir_done(teco_machine_main_t *ctx, const teco_string_t *str, GE
/*
* Null-characters must not occur in file names.
*/
- if (teco_string_contains(&home, '\0')) {
+ if (teco_string_contains(home, '\0')) {
teco_string_clear(&home);
g_set_error_literal(error, TECO_ERROR, TECO_ERROR_FAILED,
"Null-character not allowed in filenames");
@@ -1796,7 +1796,7 @@ teco_return(teco_machine_main_t *ctx, GError **error)
* command line with `}` after command-line termination.
*/
if (G_UNLIKELY(ctx == &teco_cmdline.machine &&
- teco_qreg_current && !teco_string_cmp(&teco_qreg_current->head.name, "\e", 1))) {
+ teco_qreg_current && !teco_string_cmp(teco_qreg_current->head.name, "\e", 1))) {
g_set_error_literal(error, TECO_ERROR, TECO_ERROR_FAILED,
"Not allowed to terminate command-line while "
"editing command-line replacement register");
@@ -2930,14 +2930,14 @@ teco_state_insert_initial(teco_machine_main_t *ctx, GError **error)
}
gboolean
-teco_state_insert_process(teco_machine_main_t *ctx, const teco_string_t *str,
+teco_state_insert_process(teco_machine_main_t *ctx, teco_string_t str,
gsize new_chars, GError **error)
{
g_assert(new_chars > 0);
teco_interface_ssm(SCI_BEGINUNDOACTION, 0, 0);
teco_interface_ssm(SCI_ADDTEXT, new_chars,
- (sptr_t)(str->data + str->len - new_chars));
+ (sptr_t)(str.data + str.len - new_chars));
teco_interface_ssm(SCI_ENDUNDOACTION, 0, 0);
teco_ring_dirtify();
@@ -2948,7 +2948,7 @@ teco_state_insert_process(teco_machine_main_t *ctx, const teco_string_t *str,
}
teco_state_t *
-teco_state_insert_done(teco_machine_main_t *ctx, const teco_string_t *str, GError **error)
+teco_state_insert_done(teco_machine_main_t *ctx, teco_string_t str, GError **error)
{
if (ctx->flags.mode > TECO_MODE_NORMAL)
return &teco_state_start;