__builtin_expect in catgets
Bruno Haible
haible@ilog.fr
Tue May 2 06:47:00 GMT 2000
Here is a patch to add __builtin_expect marks to the catgets subdirectory.
Also, treatment for a possible error return from __read() is added.
2000-04-30 Bruno Haible <clisp.cons.org>
* catgets/catgets.c (catopen): Use __builtin_expect where appropriate.
* catgets/open_catalog.c (__open_catalog): Likewise. Handle possible
__read error.
*** catgets/catgets.c.bak Mon Jan 31 15:50:43 2000
--- catgets/catgets.c Sun Apr 30 13:08:57 2000
***************
*** 77,83 ****
result = (__nl_catd) malloc (sizeof (*result) + cat_name_len
+ env_var_len + nlspath_len);
! if (result == NULL)
/* We cannot get enough memory. */
return (nl_catd) -1;
--- 77,83 ----
result = (__nl_catd) malloc (sizeof (*result) + cat_name_len
+ env_var_len + nlspath_len);
! if (__builtin_expect (result == NULL, 0))
/* We cannot get enough memory. */
return (nl_catd) -1;
*** catgets/open_catalog.c.bak Mon Jan 31 15:50:44 2000
--- catgets/open_catalog.c Sun Apr 30 13:17:00 2000
***************
*** 50,56 ****
__libc_lock_lock (catalog->lock);
/* Check whether there was no other thread faster. */
! if (catalog->status != closed)
/* While we waited some other thread tried to open the catalog. */
goto unlock_return;
--- 50,56 ----
__libc_lock_lock (catalog->lock);
/* Check whether there was no other thread faster. */
! if (__builtin_expect (catalog->status != closed, 0))
/* While we waited some other thread tried to open the catalog. */
goto unlock_return;
***************
*** 60,66 ****
{
const char *run_nlspath = catalog->nlspath;
#define ENOUGH(n) \
! if (bufact + (n) >=bufmax) \
{ \
char *old_buf = buf; \
bufmax += 256 + (n); \
--- 60,66 ----
{
const char *run_nlspath = catalog->nlspath;
#define ENOUGH(n) \
! if (__builtin_expect (bufact + (n) >= bufmax, 0)) \
{ \
char *old_buf = buf; \
bufmax += 256 + (n); \
***************
*** 240,246 ****
implemented. Try to load the file. */
size_t todo;
catalog->file_ptr = malloc (st.st_size);
! if (catalog->file_ptr == NULL)
{
catalog->status = nonexisting;
goto close_unlock_return;
--- 240,246 ----
implemented. Try to load the file. */
size_t todo;
catalog->file_ptr = malloc (st.st_size);
! if (__builtin_expect (catalog->file_ptr == NULL, 0))
{
catalog->status = nonexisting;
goto close_unlock_return;
***************
*** 251,258 ****
{
size_t now = __read (fd, (((char *) &catalog->file_ptr)
+ (st.st_size - todo)), todo);
! if (now == 0)
{
free ((void *) catalog->file_ptr);
catalog->status = nonexisting;
goto close_unlock_return;
--- 251,262 ----
{
size_t now = __read (fd, (((char *) &catalog->file_ptr)
+ (st.st_size - todo)), todo);
! if (now == 0 || now == (size_t) -1)
{
+ #ifdef EINTR
+ if (now == (size_t) -1 && errno == EINTR)
+ continue;
+ #endif
free ((void *) catalog->file_ptr);
catalog->status = nonexisting;
goto close_unlock_return;
More information about the Libc-alpha
mailing list