diff options
author | Aleksey Veresov <aleksey@veresov.pro> | 2021-01-09 21:44:21 +0300 |
---|---|---|
committer | Aleksey Veresov <aleksey@veresov.pro> | 2021-01-09 21:44:21 +0300 |
commit | a0f273300aec59d31eb332e531efd8249fc67f20 (patch) | |
tree | bc97d57116225977c374721f8517611156aaf6ec | |
parent | ff592daf2d90b922f82e65f648caf27381f89590 (diff) | |
download | csx-a0f273300aec59d31eb332e531efd8249fc67f20.tar csx-a0f273300aec59d31eb332e531efd8249fc67f20.tar.xz csx-a0f273300aec59d31eb332e531efd8249fc67f20.zip |
Performance improvements.
-rw-r--r-- | include/csx.h | 4 | ||||
-rw-r--r-- | src/csx.c | 18 |
2 files changed, 7 insertions, 15 deletions
diff --git a/include/csx.h b/include/csx.h index 77b94c0..2087212 100644 --- a/include/csx.h +++ b/include/csx.h @@ -11,8 +11,8 @@ void *csx_pair(void *a, void *b, void *c, ...); typedef int *(csx_int_fn)(int num); int *csx_int(int num); -typedef double *(csx_float_fn)(double num); -double *csx_float(double num); +typedef double *(csx_real_fn)(double num); +double *csx_real(double num); void *csx_run(void *expression); @@ -188,26 +188,14 @@ csx_base_data *csx_base(csx_base_data base) int *csx_int(int num) { if (!initiated) init(); - int i; - for (i = 0; i != objslen; ++i) { - int *obj = (int *)(objs[i]) + 2; - if (type(obj) != type_int) continue; - if (*obj == num) return obj; - } int *res = new(type_int, sizeof(int)); *res = num; return res; } -double *csx_float(double num) +double *csx_real(double num) { if (!initiated) init(); - int i; - for (i = 0; i != objslen; ++i) { - double *obj = (void *)((int *)(objs[i]) + 2); - if (type(obj) != type_real) continue; - if (*obj == num) return obj; - } double *res = new(type_real, sizeof(double)); *res = num; return res; @@ -336,6 +324,10 @@ static void *base_quote(void *arg) static void *base_same(void *arg) { arg = run_each(arg); + if (type(head(arg)) == type_int) + return *(int *)head(arg) == *(int *)head(tail(arg)) ? one : null; + if (type(head(arg)) == type_real) + return *(double *)head(arg) == *(double *)head(tail(arg)) ? one : null; return head(arg) == head(tail(arg)) ? one : null; } |