From a0f273300aec59d31eb332e531efd8249fc67f20 Mon Sep 17 00:00:00 2001 From: Aleksey Veresov Date: Sat, 9 Jan 2021 21:44:21 +0300 Subject: Performance improvements. --- src/csx.c | 18 +++++------------- 1 file changed, 5 insertions(+), 13 deletions(-) (limited to 'src/csx.c') 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