[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: neat symbol speedup
From: |
Neil Jerram |
Subject: |
Re: neat symbol speedup |
Date: |
05 Oct 2001 20:23:32 +0100 |
User-agent: |
Gnus/5.0808 (Gnus v5.8.8) Emacs/20.7 |
>>>>> "Han-Wen" == Han-Wen Nienhuys <address@hidden> writes:
Han-Wen> Hi there,
Han-Wen> I present to you to the following trick. If you use a lot
Han-Wen> of constant symbols in your C code, e.g.
Han-Wen> void foo (Bar * b) { ...
Han-Wen> for (very-often)
b-> lookup_key (gh_symbol2scm("some-constant-symbol"))
Han-Wen> ... }
Han-Wen> then you can use the following trick with GCC to
Han-Wen> eliminate runtime gh_symbol2scm() calls:
Han-Wen> #define symbol2scm(x) ({ static SCM cached; \
Han-Wen> (__builtin_constant_p (x)) \ ? ((cached) ? cached :
Han-Wen> cached = gh_symbol2scm((char*)x)) \ : gh_symbol2scm(x);
Han-Wen> })
Isn't this just an application of standard common sense when looking
to improve performance? It's pretty obvious that you shouldn't do
unnecessary and repetitious computation inside a loop, especially when
it involves processing a string.
Or am I missing something extra in the GCC stuff?
Neil
- Re: neat symbol speedup,
Neil Jerram <=