This is the mail archive of the
libc-alpha@sourceware.org
mailing list for the glibc project.
Re: [RFC] Make getenv O(1)
- From: Alexander Monakov <amonakov at ispras dot ru>
- To: Ondřej Bílka <neleai at seznam dot cz>
- Cc: Rich Felker <dalias at aerifal dot cx>, Florian Weimer <fweimer at redhat dot com>, libc-alpha at sourceware dot org
- Date: Mon, 21 Oct 2013 20:55:37 +0400 (MSK)
- Subject: Re: [RFC] Make getenv O(1)
- Authentication-results: sourceware.org; auth=none
- References: <20131014155229 dot GA25159 at domone dot podge> <20131014165411 dot GZ20515 at brightrain dot aerifal dot cx> <20131014172852 dot GA26005 at domone dot podge> <52611F60 dot 3080700 at redhat dot com> <20131018124013 dot GA15803 at domone dot podge> <alpine dot LNX dot 2 dot 00 dot 1310181656380 dot 3212 at monopod dot intra dot ispras dot ru> <20131018132604 dot GA16445 at domone dot podge> <alpine dot LNX dot 2 dot 00 dot 1310181744060 dot 3212 at monopod dot intra dot ispras dot ru> <20131018140705 dot GA18542 at domone dot podge> <20131021152356 dot GQ20515 at brightrain dot aerifal dot cx> <20131021161938 dot GA26730 at domone dot podge>
On Mon, 21 Oct 2013, OndÅej BÃlka wrote:
> Why, following does not need synchronization.
>
> #define GETENV(x) ({ \
> static char *__ret = NULL; \
> if (__builtin_constant_p (x) && !__cached) \
> __ret = getenv (x) + 1; \
> __builtin_constant_p (x) ? __ret - 1: getenv (x);})
This wouldn't compile as __cached is not defined (and I'll admit I don't see
what approach you're trying to convey).
Alexander