diff options
| author | Robin Haberkorn <rhaberkorn@fmsbw.de> | 2025-12-28 16:23:22 +0100 |
|---|---|---|
| committer | Robin Haberkorn <rhaberkorn@fmsbw.de> | 2025-12-28 20:57:31 +0100 |
| commit | ea0a23645f03a42252ab1ce8df45ae4076ebae75 (patch) | |
| tree | 5fe606a9b07f2f7039b1839f9fac6bab2d212c13 /src/goto-commands.c | |
| parent | d94521fb5b5a5c3a6315c425dba5f1218f0dd323 (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/goto-commands.c')
| -rw-r--r-- | src/goto-commands.c | 14 |
1 files changed, 7 insertions, 7 deletions
diff --git a/src/goto-commands.c b/src/goto-commands.c index 6fdaffc..aad3668 100644 --- a/src/goto-commands.c +++ b/src/goto-commands.c @@ -75,7 +75,7 @@ teco_state_label_input(teco_machine_main_t *ctx, gunichar chr, GError **error) teco_goto_table_undo_remove(&ctx->goto_table, ctx->goto_label.data, ctx->goto_label.len); if (teco_goto_skip_label.len > 0 && - !teco_string_cmp(&ctx->goto_label, teco_goto_skip_label.data, teco_goto_skip_label.len)) { + !teco_string_cmp(ctx->goto_label, teco_goto_skip_label.data, teco_goto_skip_label.len)) { teco_undo_string_own(teco_goto_skip_label); memset(&teco_goto_skip_label, 0, sizeof(teco_goto_skip_label)); teco_undo_gssize(teco_goto_backup_pc) = -1; @@ -118,12 +118,12 @@ TECO_DEFINE_STATE(teco_state_label, ); static teco_state_t * -teco_state_goto_done(teco_machine_main_t *ctx, const teco_string_t *str, GError **error) +teco_state_goto_done(teco_machine_main_t *ctx, teco_string_t str, GError **error) { if (ctx->flags.mode > TECO_MODE_NORMAL) return &teco_state_start; - if (!str->len) { + if (!str.len) { /* you can still write @O/,/, though... */ g_set_error_literal(error, TECO_ERROR, TECO_ERROR_FAILED, "No labels given for <O>"); @@ -141,9 +141,9 @@ teco_state_goto_done(teco_machine_main_t *ctx, const teco_string_t *str, GError */ teco_string_t label = {NULL, 0}; while (value >= 0) { - label.data = label.data ? label.data+label.len+1 : str->data; - const gchar *p = label.data ? memchr(label.data, ',', str->len - (label.data - str->data)) : NULL; - label.len = p ? p - label.data : str->len - (label.data - str->data); + label.data = label.data ? label.data+label.len+1 : str.data; + const gchar *p = label.data ? memchr(label.data, ',', str.len - (label.data - str.data)) : NULL; + label.len = p ? p - label.data : str.len - (label.data - str.data); value--; @@ -178,7 +178,7 @@ teco_state_goto_done(teco_machine_main_t *ctx, const teco_string_t *str, GError /* in cmdline.c */ gboolean teco_state_goto_process_edit_cmd(teco_machine_main_t *ctx, teco_machine_t *parent_ctx, gunichar chr, GError **error); -gboolean teco_state_goto_insert_completion(teco_machine_main_t *ctx, const teco_string_t *str, +gboolean teco_state_goto_insert_completion(teco_machine_main_t *ctx, teco_string_t str, GError **error); /*$ "O" ":O" goto |
