Skip to content

Commit 9fd2842

Browse files
committed
unlikely
1 parent ac2c33f commit 9fd2842

1 file changed

Lines changed: 8 additions & 2 deletions

File tree

simplecpp.cpp

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,12 @@
5858
# include <sys/stat.h>
5959
#endif
6060

61+
#ifdef __GNUC__
62+
# define unlikely(x) __builtin_expect(!!(x), 0)
63+
#else
64+
# define unlikely(x) (x)
65+
#endif
66+
6167
static bool isHex(const std::string &s)
6268
{
6369
return s.size()>2 && (s.compare(0,2,"0x")==0 || s.compare(0,2,"0X")==0);
@@ -502,14 +508,14 @@ class FileStreamBuffered : public simplecpp::TokenList::Stream {
502508
private:
503509
void read_internal() {
504510
// check if we are in the last chunk
505-
if (buf_idx >= buf_len) {
511+
if (unlikely(buf_idx >= buf_len)) {
506512
if (buf_len != sizeof(buf)) {
507513
lastStatus = EOF;
508514
return;
509515
}
510516
}
511517

512-
if (buf_idx == -1 || buf_idx == buf_len)
518+
if (unlikely(buf_idx == -1 || buf_idx == buf_len))
513519
{
514520
buf_idx = 0;
515521
buf_len = fread(buf, 1, sizeof(buf), file);

0 commit comments

Comments
 (0)