session OPTIMIZE deleting from an array
Instead of moving all the items after the
deleted one, place only the last one there
instead.
diff --git a/src/session_client_ssh.c b/src/session_client_ssh.c
index 3fabdd1..644229a 100644
--- a/src/session_client_ssh.c
+++ b/src/session_client_ssh.c
@@ -603,7 +603,7 @@
--ssh_opts.key_count;
- memmove(ssh_opts.keys + idx, ssh_opts.keys + idx + 1, (ssh_opts.key_count - idx) * sizeof *ssh_opts.keys);
+ memcpy(ssh_opts.keys + idx, ssh_opts.keys + ssh_opts.key_count, sizeof *ssh_opts.keys);
ssh_opts.keys = realloc(ssh_opts.keys, ssh_opts.key_count * sizeof *ssh_opts.keys);
return 0;
diff --git a/src/session_server.c b/src/session_server.c
index 2f86c1f..a0f8239 100644
--- a/src/session_server.c
+++ b/src/session_server.c
@@ -480,7 +480,7 @@
for (i = 0; i < ps->session_count; ++i) {
if (ps->sessions[i].session == session) {
--ps->session_count;
- memmove(&ps->sessions[i], &ps->sessions[i + 1], ps->session_count - i);
+ memcpy(&ps->sessions[i], &ps->sessions[ps->session_count], sizeof *ps->sessions);
return 0;
}
}
@@ -774,7 +774,7 @@
free(server_opts.binds[i].address);
--server_opts.bind_count;
- memmove(&server_opts.binds[i], &server_opts.binds[i + 1], (server_opts.bind_count - i) * sizeof *server_opts.binds);
+ memcpy(&server_opts.binds[i], &server_opts.binds[server_opts.bind_count], sizeof *server_opts.binds);
ret = 0;
}
diff --git a/src/session_server_ssh.c b/src/session_server_ssh.c
index 1a4f28b..a33405c 100644
--- a/src/session_server_ssh.c
+++ b/src/session_server_ssh.c
@@ -193,7 +193,7 @@
lydict_remove(server_opts.ctx, ssh_opts.authkeys[i].username);
--ssh_opts.authkey_count;
- memmove(&ssh_opts.authkeys[i], &ssh_opts.authkeys[i + 1], (ssh_opts.authkey_count - i) * sizeof *ssh_opts.authkeys);
+ memcpy(&ssh_opts.authkeys[i], &ssh_opts.authkeys[ssh_opts.authkey_count], sizeof *ssh_opts.authkeys);
ret = 0;
}
diff --git a/src/session_server_tls.c b/src/session_server_tls.c
index b0116aa..d5adf0b 100644
--- a/src/session_server_tls.c
+++ b/src/session_server_tls.c
@@ -1115,7 +1115,7 @@
lydict_remove(server_opts.ctx, tls_opts.ctn[i].name);
--tls_opts.ctn_count;
- memmove(&tls_opts.ctn[i], &tls_opts.ctn[i + 1], (tls_opts.ctn_count - i) * sizeof *tls_opts.ctn);
+ memcpy(&tls_opts.ctn[i], &tls_opts.ctn[tls_opts.ctn_count], sizeof *tls_opts.ctn);
ret = 0;
}