From 7e0108c990397a7d8a87c7b5b0a568fbe6b1d8b4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hugo=20H=C3=B6rnquist?= Date: Wed, 1 May 2019 20:51:08 +0200 Subject: Micro-optimizations with huge impact. --- src/guile_interface.scm.c | 20 +++++++++++++++++--- src/main.c | 2 +- src/vcal.c | 2 ++ src/vcal.h | 1 + 4 files changed, 21 insertions(+), 4 deletions(-) diff --git a/src/guile_interface.scm.c b/src/guile_interface.scm.c index 01ec7fab..4d70c127 100644 --- a/src/guile_interface.scm.c +++ b/src/guile_interface.scm.c @@ -4,6 +4,7 @@ #include "guile_type_helpers.h" static SCM vcomponent_type; +static SCM content_set_lists; void init_vcomponent_type (void) { SCM name = scm_from_utf8_symbol("vcomponent"); @@ -43,7 +44,7 @@ SCM_DEFINE (vcomponent_get_attribute, "%vcomponent-get-attribute", 2, 0, 0, scm_assert_foreign_object_type (vcomponent_type, calendar); vcomponent* cal = scm_foreign_object_ref (calendar, 0); - char* key = scm_to_utf8_stringn(scm_string_upcase(attr), NULL); + const char* key = scm_i_string_chars (attr); content_line* c = get_attributes (cal, key); if (c == NULL) { @@ -52,7 +53,11 @@ SCM_DEFINE (vcomponent_get_attribute, "%vcomponent-get-attribute", 2, 0, 0, c->cval->key.scm = SCM_BOOL_F; } - free(key); + SCM ptr = scm_from_pointer(c, NULL); + SCM ret = scm_hashq_ref (content_set_lists, ptr, SCM_BOOL_F); + if (! scm_is_false (ret)) { + return ret; + } SCM val, proplist; SCM attrroot = scm_list_1(SCM_BOOL_F); @@ -96,6 +101,9 @@ SCM_DEFINE (vcomponent_get_attribute, "%vcomponent-get-attribute", 2, 0, 0, /* create circular list */ scm_set_cdr_x (attrroot, attrlist); + + scm_hashq_set_x (content_set_lists, ptr, attrlist); + return attrlist; } @@ -178,7 +186,12 @@ SCM_DEFINE(vcomponent_typeof, "%vcomponent-get-type", 1, 0, 0, { scm_assert_foreign_object_type (vcomponent_type, component); vcomponent* comp = scm_foreign_object_ref (component, 0); - return scm_from_utf8_symbol(comp->type); + + if (comp->scmtype == NULL) { + comp->scmtype = scm_from_utf8_symbol(comp->type); + } + + return comp->scmtype; } SCM_DEFINE(vcomponent_set_type_x, "%vcomponent-set-type!", 2, 0, 0, @@ -240,6 +253,7 @@ SCM_DEFINE(vcomponent_shallow_copy, "%vcomponent-shallow-copy", 1, 0, 0, void init_lib (void) { init_vcomponent_type(); + content_set_lists = scm_make_weak_key_hash_table (scm_from_uint(0x100)); #ifndef SCM_MAGIC_SNARFER #include "guile_interface.x" diff --git a/src/main.c b/src/main.c index fabca811..4d8da7d3 100644 --- a/src/main.c +++ b/src/main.c @@ -32,7 +32,7 @@ int arg_shift (arg* a) { */ int run_tests() { NEW(vcomponent, c); - INFO(All the following should print a valid pointer ≠ 0x0); + INFO(All the following should print a valid pointer != 0x0); GETSET(c, "FILENAME"); GETSET(c, "X-HNH-FILENAME"); GETSET(c, "DATA"); diff --git a/src/vcal.c b/src/vcal.c index c0ac6182..3c9885ba 100644 --- a/src/vcal.c +++ b/src/vcal.c @@ -42,6 +42,7 @@ INIT_F(vcomponent) { self->parent = NULL; self->scm = NULL; + self->scmtype = NULL; return 0; @@ -74,6 +75,7 @@ INIT_F(vcomponent, const char* type, const char* filename) { self->parent = NULL; self->scm = NULL; + self->scmtype = NULL; return 0; } diff --git a/src/vcal.h b/src/vcal.h index c9a0272f..2a3ad294 100644 --- a/src/vcal.h +++ b/src/vcal.h @@ -80,6 +80,7 @@ struct s_vcomponent { * vcomponent. */ SCM scm; + SCM scmtype; }; #define FCHILD(v) FIRST_V(&(v)->components) -- cgit v1.2.3