This is the mail archive of the
libc-alpha@sourceware.cygnus.com
mailing list for the glibc project.
Re: __builtin_expect in gettext
- To: libc-alpha at sourceware dot cygnus dot com
- Subject: Re: __builtin_expect in gettext
- From: Bruno Haible <haible at ilog dot fr>
- Date: Tue, 2 May 2000 16:11:54 +0200 (MET DST)
> We don't need to add checks against NULL.
OK, here is a revised patch.
2000-04-29 Bruno Haible <clisp.cons.org>
* intl/gettextP.h (__builtin_expect): Define as empty if not a
compiler builtin.
* intl/loadinfo.h (__builtin_expect): Likewise.
* intl/dcigettext.c (dcigettext, _nl_find_msg): Use
__builtin_expect where appropriate.
* intl/loadmsgcat.c (_nl_load_domain): Likewise.
* intl/localealias.c (extend_alias_table): Return an error indicator.
(read_alias_file): Bail out if extend_alias_table fails.
*** intl/gettextP.h.bak Mon Feb 28 11:34:05 2000
--- intl/gettextP.h Sun Apr 30 00:25:13 2000
***************
*** 44,49 ****
--- 44,55 ----
# define internal_function
#endif
+ /* Tell the compiler when a conditional or integer expression is
+ almost always true or almost always false. */
+ #ifndef HAVE_BUILTIN_EXPECT
+ # define __builtin_expect(expr, val) (expr)
+ #endif
+
#ifndef W
# define W(flag, data) ((flag) ? SWAP (data) : (data))
#endif
*** intl/loadinfo.h.bak Sun Apr 23 18:01:14 2000
--- intl/loadinfo.h Sun Apr 30 10:30:44 2000
***************
*** 32,37 ****
--- 32,43 ----
# define internal_function
#endif
+ /* Tell the compiler when a conditional or integer expression is
+ almost always true or almost always false. */
+ #ifndef HAVE_BUILTIN_EXPECT
+ # define __builtin_expect(expr, val) (expr)
+ #endif
+
/* Encoding of locale name parts. */
#define CEN_REVISION 1
#define CEN_SPONSOR 2
*** intl/dcigettext.c.bak Sat Apr 29 09:02:02 2000
--- intl/dcigettext.c Sun Apr 30 00:21:55 2000
***************
*** 605,611 ****
/* Insert the entry in the search tree. */
foundp = (struct known_translation_t **)
tsearch (newp, &root, transcmp);
! if (&newp != foundp)
/* The insert failed. */
free (newp);
}
--- 607,613 ----
/* Insert the entry in the search tree. */
foundp = (struct known_translation_t **)
tsearch (newp, &root, transcmp);
! if (__builtin_expect (&newp != foundp, 0))
/* The insert failed. */
free (newp);
}
***************
*** 751,757 ****
/* Mark that we didn't succeed allocating a table. */
domain->conv_tab = (char **) -1;
! if (domain->conv_tab == (char **) -1)
/* Nothing we can do, no more memory. */
goto converted;
--- 753,759 ----
/* Mark that we didn't succeed allocating a table. */
domain->conv_tab = (char **) -1;
! if (__builtin_expect (domain->conv_tab == (char **) -1, 0))
/* Nothing we can do, no more memory. */
goto converted;
*** intl/loadmsgcat.c.bak Sun Apr 23 18:39:06 2000
--- intl/loadmsgcat.c Sun Apr 30 00:14:31 2000
***************
*** 138,146 ****
return;
/* We must know about the size of the file. */
! if (fstat (fd, &st) != 0
! || (size = (size_t) st.st_size) != st.st_size
! || size < sizeof (struct mo_file_header))
{
/* Something went wrong. */
close (fd);
--- 142,150 ----
return;
/* We must know about the size of the file. */
! if (__builtin_expect (fstat (fd, &st) != 0, 0)
! || __builtin_expect ((size = (size_t) st.st_size) != st.st_size, 0)
! || __builtin_expect (size < sizeof (struct mo_file_header), 0))
{
/* Something went wrong. */
close (fd);
***************
*** 153,159 ****
data = (struct mo_file_header *) mmap (NULL, size, PROT_READ,
MAP_PRIVATE, fd, 0);
! if (data != (struct mo_file_header *) -1)
{
/* mmap() call was successful. */
close (fd);
--- 157,163 ----
data = (struct mo_file_header *) mmap (NULL, size, PROT_READ,
MAP_PRIVATE, fd, 0);
! if (__builtin_expect (data != (struct mo_file_header *) -1, 1))
{
/* mmap() call was successful. */
close (fd);
***************
*** 193,199 ****
/* Using the magic number we can test whether it really is a message
catalog file. */
! if (data->magic != _MAGIC && data->magic != _MAGIC_SWAPPED)
{
/* The magic number is wrong: not a message catalog file. */
#ifdef HAVE_MMAP
--- 204,211 ----
/* Using the magic number we can test whether it really is a message
catalog file. */
! if (__builtin_expect (data->magic != _MAGIC && data->magic != _MAGIC_SWAPPED,
! 0))
{
/* The magic number is wrong: not a message catalog file. */
#ifdef HAVE_MMAP
*** intl/localealias.c.bak Mon Feb 28 11:34:06 2000
--- intl/localealias.c Sun Apr 30 00:02:31 2000
***************
*** 162,168 ****
/* Prototypes for local functions. */
static size_t read_alias_file PARAMS ((const char *fname, int fname_len))
internal_function;
! static void extend_alias_table PARAMS ((void));
static int alias_compare PARAMS ((const struct alias_map *map1,
const struct alias_map *map2));
--- 162,168 ----
/* Prototypes for local functions. */
static size_t read_alias_file PARAMS ((const char *fname, int fname_len))
internal_function;
! static int extend_alias_table PARAMS ((void));
static int alias_compare PARAMS ((const struct alias_map *map1,
const struct alias_map *map2));
***************
*** 326,332 ****
*cp++ = '\0';
if (nmap >= maxmap)
! extend_alias_table ();
alias_len = strlen (alias) + 1;
value_len = strlen (value) + 1;
--- 330,340 ----
*cp++ = '\0';
if (nmap >= maxmap)
! if (__builtin_expect (extend_alias_table (), 0))
! {
! FREE_BLOCKS (block_list);
! return added;
! }
alias_len = strlen (alias) + 1;
value_len = strlen (value) + 1;
***************
*** 374,380 ****
}
! static void
extend_alias_table ()
{
size_t new_size;
--- 382,388 ----
}
! static int
extend_alias_table ()
{
size_t new_size;
***************
*** 385,394 ****
* sizeof (struct alias_map)));
if (new_map == NULL)
/* Simply don't extend: we don't have any more core. */
! return;
map = new_map;
maxmap = new_size;
}
--- 393,403 ----
* sizeof (struct alias_map)));
if (new_map == NULL)
/* Simply don't extend: we don't have any more core. */
! return -1;
map = new_map;
maxmap = new_size;
+ return 0;
}