From: James Tirta Halim <tirtajames45@gmail.com>
To: libc-alpha@sourceware.org
Cc: James Tirta Halim <tirtajames45@gmail.com>
Subject: [PATCH] ftw.c: Use unlikely for unlikely taken branches such that taken ones are placed closer
Date: Tue, 3 Oct 2023 10:40:56 +0700 [thread overview]
Message-ID: <20231003034056.140938-1-tirtajames45@gmail.com> (raw)
---
io/ftw.c | 12 ++++++------
1 file changed, 6 insertions(+), 6 deletions(-)
diff --git a/io/ftw.c b/io/ftw.c
index a72c7d5171..94fb2842d2 100644
--- a/io/ftw.c
+++ b/io/ftw.c
@@ -209,7 +209,7 @@ ftw_allocate (struct ftw_data *data, size_t newsize)
void *newp = realloc (data->dirstreams, data->maxdir
* sizeof (struct dir_data *)
+ newsize);
- if (newp == NULL)
+ if (__glibc_unlikely(newp == NULL))
return false;
data->dirstreams = newp;
data->dirbufsize = newsize;
@@ -255,7 +255,7 @@ static int
add_object (struct ftw_data *data, struct STRUCT_STAT *st)
{
struct known_object *newp = malloc (sizeof (struct known_object));
- if (newp == NULL)
+ if (__glibc_unlikely(newp == NULL))
return -1;
newp->dev = st->st_dev;
newp->ino = st->st_ino;
@@ -287,7 +287,7 @@ open_dir_stream (int *dfdp, struct ftw_data *data, struct dir_data *dirp)
size_t bufsize = 1024;
char *buf = malloc (bufsize);
- if (buf == NULL)
+ if (__glibc_unlikely(buf == NULL))
result = -1;
else
{
@@ -298,12 +298,12 @@ open_dir_stream (int *dfdp, struct ftw_data *data, struct dir_data *dirp)
while ((d = __readdir64 (st)) != NULL)
{
size_t this_len = NAMLEN (d);
- if (actsize + this_len + 2 >= bufsize)
+ if (glibc_unlikely(actsize + this_len + 2 >= bufsize))
{
char *newp;
bufsize += MAX (1024, 2 * this_len);
newp = (char *) realloc (buf, bufsize);
- if (newp == NULL)
+ if (__glibc_unlikely(newp == NULL))
{
/* No more memory. */
int save_err = errno;
@@ -325,7 +325,7 @@ open_dir_stream (int *dfdp, struct ftw_data *data, struct dir_data *dirp)
/* Shrink the buffer to what we actually need. */
void *content = realloc (buf, actsize);
data->dirstreams[data->actdir]->content = content;
- if (content == NULL)
+ if (__glibc_unlikely(content == NULL))
{
int save_err = errno;
free (buf);
--
2.42.0
next reply other threads:[~2023-10-03 3:41 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-10-03 3:40 James Tirta Halim [this message]
2023-10-03 6:28 ` Xi Ruoyao
2023-10-03 7:47 ` Andreas Schwab
2023-10-03 10:44 Wilco Dijkstra
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20231003034056.140938-1-tirtajames45@gmail.com \
--to=tirtajames45@gmail.com \
--cc=libc-alpha@sourceware.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).