Faster strfold function.
This commit is contained in:
19
mpc.c
19
mpc.c
@@ -2301,14 +2301,19 @@ mpc_val_t *mpcf_trd_free(int n, mpc_val_t **xs) { return mpcf_nth_free(n, xs, 2)
|
|||||||
|
|
||||||
mpc_val_t *mpcf_strfold(int n, mpc_val_t **xs) {
|
mpc_val_t *mpcf_strfold(int n, mpc_val_t **xs) {
|
||||||
int i;
|
int i;
|
||||||
char *x = calloc(1, 1);
|
size_t l;
|
||||||
|
|
||||||
for (i = 0; i < n; i++) {
|
if (n == 0) { return calloc(1, 1); }
|
||||||
x = realloc(x, strlen(x) + strlen(xs[i]) + 1);
|
|
||||||
strcat(x, xs[i]);
|
for (i = 0; i < n; i++) { l += strlen(xs[i]); }
|
||||||
free(xs[i]);
|
|
||||||
|
xs[0] = realloc(xs[0], l + 1);
|
||||||
|
|
||||||
|
for (i = 1; i < n; i++) {
|
||||||
|
strcat(xs[0], xs[i]); free(xs[i]);
|
||||||
}
|
}
|
||||||
return x;
|
|
||||||
|
return xs[0];
|
||||||
}
|
}
|
||||||
|
|
||||||
mpc_val_t *mpcf_maths(int n, mpc_val_t **xs) {
|
mpc_val_t *mpcf_maths(int n, mpc_val_t **xs) {
|
||||||
|
Reference in New Issue
Block a user