From a0f273300aec59d31eb332e531efd8249fc67f20 Mon Sep 17 00:00:00 2001 From: Aleksey Veresov Date: Sat, 9 Jan 2021 21:44:21 +0300 Subject: Performance improvements. --- include/csx.h | 4 ++-- 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); diff --git a/src/csx.c b/src/csx.c index 9f83fec..73f8690 100644 --- a/src/csx.c +++ b/src/csx.c @@ -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; } -- cgit v1.2.3